Skip to content

Commit bbc0420

Browse files
authored
Merge pull request #1 from keploy/add-docker
chore: refactor and add docker build pipeline
2 parents 5ba9e62 + 0c6fece commit bbc0420

File tree

14 files changed

+113
-292
lines changed

14 files changed

+113
-292
lines changed

.github/workflows/docker.yaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Docker Build and Push
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
tags: [ 'v*.*.*' ]
11+
12+
13+
env:
14+
# Use docker.io for Docker Hub if empty
15+
REGISTRY: ghcr.io
16+
# github.repository as <account>/<repo>
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
20+
jobs:
21+
build:
22+
23+
runs-on: [selfhosted-linux-amd64]
24+
env:
25+
GOPRIVATE: github.com/keploy
26+
permissions:
27+
contents: read
28+
packages: write
29+
# This is used to complete the identity challenge
30+
# with sigstore/fulcio when running outside of PRs.
31+
id-token: write
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v3
36+
37+
# Install the cosign tool except on PR
38+
# https://github.com/sigstore/cosign-installer
39+
- name: Install Cosign
40+
uses: sigstore/cosign-installer@v3.4.0
41+
42+
# Set up BuildKit Docker container builder to be able to build
43+
# multi-platform images and export cache
44+
# https://github.com/docker/setup-buildx-action
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
47+
48+
# Login against a Docker registry except on PR
49+
# https://github.com/docker/login-action
50+
- name: Log into registry ${{ env.REGISTRY }}
51+
if: github.event_name != 'pull_request'
52+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
53+
with:
54+
registry: ${{ env.REGISTRY }}
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
58+
# Extract metadata (tags, labels) for Docker
59+
# https://github.com/docker/metadata-action
60+
- name: Extract Docker metadata
61+
id: meta
62+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
63+
with:
64+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
65+
66+
# Build and push Docker image with Buildx (don't push on PR)
67+
# https://github.com/docker/build-push-action
68+
- name: Build and push Docker image
69+
id: build-and-push
70+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
71+
with:
72+
context: .
73+
platforms: linux/arm64
74+
push: ${{ github.event_name != 'pull_request' }}
75+
tags: ${{ steps.meta.outputs.tags }}
76+
labels: ${{ steps.meta.outputs.labels }}
77+
cache-from: type=gha
78+
cache-to: type=gha,mode=max
79+
80+
# Sign the resulting Docker image digest except on PRs.
81+
# This will only write to the public Rekor transparency log when the Docker
82+
# repository is public to avoid leaking data. If you would like to publish
83+
# transparency data even for private images, pass --force to cosign below.
84+
# https://github.com/sigstore/cosign
85+
- name: Sign the published Docker image
86+
if: ${{ github.event_name != 'pull_request' }}
87+
env:
88+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
89+
TAGS: ${{ steps.meta.outputs.tags }}
90+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
91+
# This step uses the identity token to provision an ephemeral certificate
92+
# against the sigstore community Fulcio instance.
93+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build stage
2-
FROM golang:1.22-alpine AS builder
2+
FROM golang:1.24-alpine AS builder
33

44
# Add git for potential dependencies
55
RUN apk add --no-cache git
@@ -23,7 +23,7 @@ COPY . .
2323
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
2424

2525
# Final stage
26-
FROM alpine:3.19
26+
FROM alpine
2727

2828
# Add ca-certificates for HTTPS calls to GitHub API
2929
RUN apk --no-cache add ca-certificates

coverage.out

Lines changed: 0 additions & 271 deletions
This file was deleted.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/sonichigo/gitstats
1+
module github.com/keploy/gitstats
22

3-
go 1.22.5
3+
go 1.24

handlers/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strconv"
88
"strings"
99

10-
cu "github.com/sonichigo/gitstats/common"
10+
cu "github.com/keploy/gitstats/common"
1111
)
1212

1313
func HandleRepoStats(w http.ResponseWriter, r *http.Request) {

handlers/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"sort"
1212
"time"
1313

14-
cu "github.com/sonichigo/gitstats/common"
14+
cu "github.com/keploy/gitstats/common"
1515
)
1616

1717
func calculateDownloadStats(releases []cu.Release) *cu.DownloadStats {

handlers/utils_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
cu "github.com/sonichigo/gitstats/common"
9+
cu "github.com/keploy/gitstats/common"
1010
)
1111

1212
// Mock HTTP client and server setup for testing
@@ -35,7 +35,6 @@ func TestCalculateDownloadStats(t *testing.T) {
3535
}
3636
}
3737

38-
3938
func TestExtractRepoInfo(t *testing.T) {
4039
tests := []struct {
4140
url string
@@ -62,12 +61,12 @@ func TestExtractRepoInfo(t *testing.T) {
6261

6362
// Test generated using Keploy
6463
func TestExtractRepoInfo_ValidURL(t *testing.T) {
65-
owner, repo, err := extractRepoInfo("https://github.com/sonichigo/gitstats")
64+
owner, repo, err := extractRepoInfo("https://github.com/keploy/gitstats")
6665
if err != nil {
6766
t.Errorf("Expected no error, got %v", err)
6867
}
69-
if owner != "sonichigo" || repo != "gitstats" {
70-
t.Errorf("Expected owner 'sonichigo' and repo 'gitstats', got owner '%s' and repo '%s'", owner, repo)
68+
if owner != "keploy" || repo != "gitstats" {
69+
t.Errorf("Expected owner 'keploy' and repo 'gitstats', got owner '%s' and repo '%s'", owner, repo)
7170
}
7271
}
7372

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"log"
55
"net/http"
66

7-
routes "github.com/sonichigo/gitstats/routes"
7+
routes "github.com/keploy/gitstats/routes"
88
)
99

1010
func main() {

routes/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package routes
33
import (
44
"net/http"
55

6-
handler "github.com/sonichigo/gitstats/handlers"
6+
handler "github.com/keploy/gitstats/handlers"
77
)
88

99
func SetupRoutes() {

web/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="author" content="Animesh Pathak">
88
<meta name="viewport" content="width=device-width, initial-scale=1.0">
99
<link type="image/png" sizes="120x120" rel="icon" href="../images/icons8-github-120.png">
10-
<title>GitHub Stats - by Sonichigo</title>
10+
<title>GitHub Stats - by keploy</title>
1111
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.6.2/axios.min.js"></script>
1212
<style>
1313
/* Existing styles */
@@ -193,7 +193,7 @@
193193
<body>
194194
<nav class="navbar">
195195
<div class="logo">
196-
<a href="https://github.com/sonichigo/gitstats">
196+
<a href="https://github.com/keploy/gitstats">
197197
<svg height="32" viewBox="0 0 16 16" version="1.1" width="32">
198198
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path>
199199
</svg>

0 commit comments

Comments
 (0)