From 488d2acb01d2b3798a5ee8320a325fe9f38e337e Mon Sep 17 00:00:00 2001 From: bakito Date: Mon, 14 Mar 2022 20:08:55 +0100 Subject: [PATCH] build alpine image - fixes #65 --- .github/workflows/publish.yml | 58 ++++++++++++++++++++++++++++++++++- Dockerfile.alpine | 29 ++++++++++++++++++ Makefile | 8 +++-- 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.alpine diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d5bc560..d99758c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,7 @@ on: - published jobs: - main: + scratch: runs-on: ubuntu-latest steps: - name: Get current date @@ -31,6 +31,7 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push ${{github.event.release.tag_name }} id: docker_build_release uses: docker/build-push-action@v2 @@ -56,5 +57,60 @@ jobs: build-args: | VERSION=main BUILD=${{ steps.date.outputs.date }} + - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} + + alpine: + runs-on: ubuntu-latest + steps: + - name: Get current date + id: date + run: echo "::set-output name=date::$(date --utc +%Y-%m-%dT%H:%M:%SZ)" + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to Quay + uses: docker/login-action@v1 + with: + registry: quay.io + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + - name: Login to ghcr.io + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push ${{github.event.release.tag_name }} alpine + id: docker_build_alpine_release + uses: docker/build-push-action@v2 + if: ${{ github.event.release.tag_name != '' }} + with: + pull: true + push: true + tags: quay.io/bakito/adguardhome-sync:alpine-latest,quay.io/bakito/adguardhome-sync:alpine-${{ github.event.release.tag_name }},ghcr.io/bakito/adguardhome-sync:alpine-latest,ghcr.io/bakito/adguardhome-sync:alpine-${{ github.event.release.tag_name }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 + file: Dockerfile.alpine + build-args: | + VERSION=${{ github.event.release.tag_name }} + BUILD=${{ steps.date.outputs.date }} + + - name: Build and push main alpine + id: docker_build_alpine_main + uses: docker/build-push-action@v2 + if: ${{ github.event.release.tag_name == '' }} + with: + pull: true + push: true + tags: quay.io/bakito/adguardhome-sync:alpine-main,ghcr.io/bakito/adguardhome-sync:alpine-main + platforms: linux/amd64,linux/arm64,linux/arm/v7 + file: Dockerfile.alpine + build-args: | + VERSION=main + BUILD=${{ steps.date.outputs.date }} + + - name: Image digest alpine + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..cfca88b --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,29 @@ +FROM golang:1.17 as builder + +WORKDIR /go/src/app + +RUN apt-get update && apt-get install -y upx + +ARG VERSION=main +ARG BUILD="N/A" + +ENV GO111MODULE=on \ + CGO_ENABLED=0 \ + GOOS=linux + +COPY . /go/src/app/ + +RUN go build -a -installsuffix cgo -ldflags="-w -s -X github.com/bakito/adguardhome-sync/version.Version=${VERSION} -X github.com/bakito/adguardhome-sync/version.Build=${BUILD}" -o adguardhome-sync . \ + && upx -q adguardhome-sync + +# application image +FROM alpine:latest +WORKDIR /opt/go + +LABEL maintainer="bakito " +EXPOSE 8080 +ENTRYPOINT ["/opt/go/adguardhome-sync"] +CMD ["run", "--config", "/config/adguardhome-sync.yaml"] +COPY --from=builder /go/src/app/adguardhome-sync /opt/go/adguardhome-sync +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +USER 1001 diff --git a/Makefile b/Makefile index 7655fac..4c3df33 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ tidy: test: test-ci fmt # Run ci tests -test-ci: mocks tidy +test-ci: mocks tidy alpine-docker go test ./... -coverprofile=coverage.out go tool cover -func=coverage.out @@ -47,4 +47,8 @@ __check_defined = \ build-image: $(call check_defined, AGH_SYNC_VERSION) - podman build --build-arg VERSION=${AGH_SYNC_VERSION} --build-arg BUILD=$(shell date -u +'%Y-%m-%dT%H:%M:%S.%3NZ') --name adgardhome-replica -t ghcr.io/bakito/adguardhome-sync:${AGH_SYNC_VERSION} . \ No newline at end of file + podman build --build-arg VERSION=${AGH_SYNC_VERSION} --build-arg BUILD=$(shell date -u +'%Y-%m-%dT%H:%M:%S.%3NZ') --name adgardhome-replica -t ghcr.io/bakito/adguardhome-sync:${AGH_SYNC_VERSION} . + +alpine-docker: + cp Dockerfile Dockerfile.alpine + sed -i 's/FROM scratch/FROM alpine:latest/g' Dockerfile.alpine