Skip to content

Commit

Permalink
an attempt to speed up github action
Browse files Browse the repository at this point in the history
  • Loading branch information
yusing committed Sep 28, 2024
1 parent 91e7f48 commit fc6a6aa
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 7 deletions.
57 changes: 55 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ name: Docker Image CI

on:
push:
tags: ["*"]
# tags: ["*"]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
CGO_ENABLED: 0
BUILD_FLAGS: -ldflags '-w -s' -pgo=auto

jobs:
build:
Expand All @@ -30,9 +32,58 @@ jobs:
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
platform=${{ matrix.platform.name }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set GOARCH and GOARM
run: |
case "${{ matrix.platform }}" in
linux/amd64)
echo "GOARCH=amd64" >> $GITHUB_ENV
;;
linux/arm/v6)
echo "GOARCH=arm" >> $GITHUB_ENV
echo "GOARM=6" >> $GITHUB_ENV
;;
linux/arm/v7)
echo "GOARCH=arm" >> $GITHUB_ENV
echo "GOARM=7" >> $GITHUB_ENV
;;
linux/arm64)
echo "GOARCH=arm64" >> $GITHUB_ENV
;;
esac
echo "OUTPUT=/tmp/go-proxy-${{ env.PLATFORM_PAIR }}" >> $GITHUB_ENV
- name: Print GOARCH and GOARM
run: |
echo "GOARCH: $GOARCH"
echo "GOARM: $GOARM"
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache-dependency-path: go.sum

- name: Display Go version
run: go version

- name: Setup dependencies
run: go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get

- name: Build the go-proxy
run: |
go build -v ${{ env.BUILD_FLAGS }} -o ${{ env.OUTPUT }} ./cmd
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: go-proxy-${{ env.PLATFORM_PAIR }}
path: ${{ env.OUTPUT }}
if-no-files-found: error

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand All @@ -59,6 +110,8 @@ jobs:
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
file: gha.Dockerfile
build-args: GOPROXY_BIN=${{ env.OUTPUT }}
cache-from: type=gha
cache-to: type=gha,mode=max

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RUN --mount=type=cache,target="/go/pkg/mod" \
FROM scratch

LABEL maintainer="[email protected]"
LABEL proxy.exclude=1

# copy timezone data
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
Expand Down
12 changes: 12 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func main() {
return
}

for _, dir := range common.RequiredDirectories {
prepareDirectory(dir)
}

err := config.Load()
if err != nil {
logrus.Warn(err)
Expand Down Expand Up @@ -188,6 +192,14 @@ func main() {
}
}

func prepareDirectory(dir string) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err = os.MkdirAll(dir, 0755); err != nil {
logrus.Fatalf("failed to create directory %s: %v", dir, err)
}
}
}

func funcName(f func()) string {
parts := strings.Split(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), "/go-proxy/")
return parts[len(parts)-1]
Expand Down
22 changes: 22 additions & 0 deletions gha.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM gcr.io/distroless/static-debian12:latest AS resources

LABEL maintainer="[email protected]"
LABEL proxy.exclude=1

ARG GOPROXY_BIN=${OUTPUT}

# copy schema directory
COPY schema /app/schema

# copy binary
COPY ${GOPROXY_BIN} /app/go-proxy

ENV DOCKER_HOST=unix:///var/run/docker.sock

EXPOSE 80
EXPOSE 8888
EXPOSE 443

WORKDIR /app

CMD ["/app/go-proxy"]
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/yusing/go-proxy

go 1.22.0
go 1.23.1

require (
github.com/docker/cli v27.3.1+incompatible
Expand All @@ -15,6 +15,7 @@ require (
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudflare/cloudflare-go v0.106.0 // indirect
Expand All @@ -29,6 +30,8 @@ require (
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/term v0.5.0 // indirect
Expand All @@ -39,10 +42,12 @@ require (
github.com/pkg/errors v0.9.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
Expand All @@ -51,6 +56,10 @@ require (
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.25.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
8 changes: 8 additions & 0 deletions internal/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const (
ErrorPagesBasePath = "error_pages"
)

var (
RequiredDirectories = []string{
ConfigBasePath,
SchemaBasePath,
ErrorPagesBasePath,
}
)

const DockerHostFromEnv = "$DOCKER_HOST"

const (
Expand Down
4 changes: 0 additions & 4 deletions internal/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/docker/docker/api/types"
"github.com/sirupsen/logrus"
U "github.com/yusing/go-proxy/internal/utils"
)

Expand All @@ -33,9 +32,6 @@ func FromDocker(c *types.Container, dockerHost string) (res Container) {
StopSignal: res.getDeleteLabel(LabelStopSignal),
Running: c.Status == "running" || c.State == "running",
}
if res.NetworkMode == "" {
logrus.Debugf("%v", res.NetworkSettings.Networks)
}
return
}

Expand Down

0 comments on commit fc6a6aa

Please sign in to comment.