From 4246b649e147e940d2aa0351cd7fe28c724dcad0 Mon Sep 17 00:00:00 2001 From: Jaime Pillora Date: Fri, 27 Jan 2023 23:02:06 +1100 Subject: [PATCH] docker alpine->google-distroless --- .github/workflows/ci.yml | 41 ++++++++++++++++++++-------------------- Dockerfile | 15 +++++++-------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f412ff3..c9c0001 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,35 +10,33 @@ jobs: name: Test strategy: matrix: - go-version: [1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x] + go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v2 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3 - name: Build run: go build -v . - name: Test run: go test -v ./... - env: - GODEBUG: x509ignoreCN=0 # ================ - # RELEASE JOB + # RELEASE JOBS # runs after a success test # only runs on push "v*" tag # ================ - release: - name: Release + release_binaries: + name: Release Binaries needs: test if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3 - name: goreleaser if: success() uses: docker://goreleaser/goreleaser:latest @@ -46,6 +44,14 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: args: release --config .github/goreleaser.yml + release_docker: + name: Release Docker Images + needs: test + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx @@ -58,21 +64,16 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Docker meta id: docker_meta - uses: crazy-max/ghaction-docker-meta@v1 + uses: docker/metadata-action@v4 with: images: jpillora/chisel tag-latest: true - # Outputs: - # jpillora/chisel:1.2.3 - # jpillora/chisel:1.2 - # jpillora/chisel:1 - # jpillora/chisel:latest - tag-semver: | - {{version}} - {{major}}.{{minor}} - {{major}} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: context: . platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/386,linux/arm/v7,linux/arm/v6 diff --git a/Dockerfile b/Dockerfile index e3e2073..ae77d37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,16 @@ # build stage -FROM golang:alpine AS build-env +FROM golang:1.19 as build LABEL maintainer="dev@jpillora.com" -RUN apk update -RUN apk add git ENV CGO_ENABLED 0 ADD . /src WORKDIR /src +RUN go mod download RUN go build \ -ldflags "-X github.com/jpillora/chisel/share.BuildVersion=$(git describe --abbrev=0 --tags)" \ -o chisel -# container stage -FROM alpine -RUN apk update && apk add --no-cache ca-certificates +# run stage +FROM gcr.io/distroless/static-debian11 WORKDIR /app -COPY --from=build-env /src/chisel /app/chisel -ENTRYPOINT ["/app/chisel"] +CMD ["/app"] +COPY --from=build /src/chisel /app/chisel +ENTRYPOINT ["/app/chisel"] \ No newline at end of file