From 4176d62fc36e88df22471fa1b9b05a595085c6c7 Mon Sep 17 00:00:00 2001 From: Sergey Kutovoy Date: Sat, 3 Aug 2024 20:15:14 +0500 Subject: [PATCH] branded, added multi-arch docker build action --- .github/workflows/build-publish.yml | 29 ++ Dockerfile | 33 ++- templates/index.html | 428 +++++++++++++++++++++++++--- 3 files changed, 434 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/build-publish.yml diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml new file mode 100644 index 0000000..964b9b9 --- /dev/null +++ b/.github/workflows/build-publish.yml @@ -0,0 +1,29 @@ +name: ci + +on: + push: + branches: ["master"] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + clubvpn/ifconfig.io:latest diff --git a/Dockerfile b/Dockerfile index 6a5085d..c05223a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,37 @@ -FROM golang:alpine AS builder +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:alpine as builder -# Set necessary environmet variables needed for our image -ENV GO111MODULE=on \ - CGO_ENABLED=0 \ - GOOS=linux \ - GOARCH=amd64 +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + + +ENV CGO_ENABLED=0 +ENV GO111MODULE=on -# Move to working directory /build WORKDIR /build -# Copy and download dependency using go mod +# Cache the download before continuing COPY go.mod . COPY go.sum . RUN go mod download -# Copy the code into the container COPY main.go . -# Build the application -RUN go build -tags=jsoniter -o main . +RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -tags=jsoniter -o main . -# Move to /dist directory as the place for resulting binary folder WORKDIR /dist -# Copy binary from build to main folder RUN cp /build/main . -# Build a small image -FROM scratch AS production +FROM --platform=${BUILDPLATFORM:-linux/amd64} gcr.io/distroless/static:nonroot +WORKDIR / COPY --from=builder /dist/main / COPY ./templates /templates COPY ./LICENSE /LICENSE -# Command to run -ENTRYPOINT ["/main"] +USER nonroot:nonroot +CMD ["/main"] \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 915150e..e8ab719 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,13 +1,262 @@ - +