build alpine image - fixes #65

This commit is contained in:
bakito
2022-03-14 20:08:55 +01:00
parent 467c7ddeb7
commit 488d2acb01
3 changed files with 92 additions and 3 deletions
+57 -1
View File
@@ -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 }}
+29
View File
@@ -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 <github@bakito.ch>"
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
+6 -2
View File
@@ -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} .
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