diff --git a/.dockerignore b/.dockerignore index e0632788..11708112 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ example .travis.yml .git +.github diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..8b11c574 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,78 @@ +name: build + +on: + push: + branches: [ master ] + tags: '*' + paths: + - '.github/workflows/build.yml' + - 'Dockerfile' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Prepare + id: prepare + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + TAG=${GITHUB_REF#refs/tags/} + echo ::set-output name=tag_name::${TAG} + echo ::set-output name=version::${TAG%-*} + else + echo ::set-output name=version::latest + fi + echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + echo ::set-output name=docker_platforms::linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + echo ::set-output name=docker_username::thomseddon + echo ::set-output name=docker_image::thomseddon/traefik-forward-auth + + - name: Set up Docker Buildx + uses: crazy-max/ghaction-docker-buildx@v1 + with: + version: latest + + - name: Checkout + uses: actions/checkout@v2 + + - name: Docker Buildx (no push) + run: | + docker buildx build --no-cache \ + --platform ${{ steps.prepare.outputs.docker_platforms }} \ + --output "type=image,push=false" \ + --build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \ + --build-arg "VCS_REF=${GITHUB_SHA::8}" \ + --build-arg "VERSION=${{ steps.prepare.outputs.version }}" \ + --tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ + --file Dockerfile . + + - name: Docker Login + if: success() + env: + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin + + - name: Docker Buildx (push) + if: success() + run: | + docker buildx build \ + --platform ${{ steps.prepare.outputs.docker_platforms }} \ + --output "type=image,push=true" \ + --build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \ + --build-arg "VCS_REF=${GITHUB_SHA::8}" \ + --build-arg "VERSION=${{ steps.prepare.outputs.version }}" \ + --tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ + --tag "${{ steps.prepare.outputs.docker_image }}:latest" \ + --file Dockerfile . + + - name: Docker Check Manifest + if: always() + run: | + docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} + + - name: Clear + if: always() + run: | + rm -f ${HOME}/.docker/config.json diff --git a/Dockerfile b/Dockerfile index b3c6e327..222c038b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN apk add --no-cache git # Copy & build ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd +RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd # Copy into scratch container FROM scratch diff --git a/Dockerfile.arm b/Dockerfile.arm deleted file mode 100644 index e10021e6..00000000 --- a/Dockerfile.arm +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.13-alpine as builder - -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth - -# Add libraries -RUN apk add --no-cache git - -# Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd - -# Copy into scratch container -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ -ENTRYPOINT ["./traefik-forward-auth"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index a9806863..00000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.13-alpine as builder - -# Setup -RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth -WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth - -# Add libraries -RUN apk add --no-cache git - -# Copy & build -ADD . /go/src/github.com/thomseddon/traefik-forward-auth/ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd - -# Copy into scratch container -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /traefik-forward-auth ./ -ENTRYPOINT ["./traefik-forward-auth"]