Skip to content

Commit

Permalink
docker multiarch image
Browse files Browse the repository at this point in the history
  • Loading branch information
vsimakhin committed Nov 10, 2024
1 parent bf64391 commit bfeb843
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
25 changes: 16 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
Expand Down Expand Up @@ -61,22 +61,29 @@ jobs:
upload_url: ${{ github.event.release.upload_url }}
asset_path: dist/web-logbook-windows-amd64.zip

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Extract Docker tag
id: extract_tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract tag name
id: extract_tag
run: echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"


- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/build.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
vsimakhin/web-logbook:${{ steps.extract_tag.outputs.tag }}
vsimakhin/web-logbook:latest
vsimakhin/web-logbook:${{ env.TAG }}
vsimakhin/web-logbook:latest
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ build_windows_amd64:
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); mv $(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) $(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME).exe; zip -r $(BINARY_NAME)-$$OS-$$ARCH.zip $(BINARY_NAME)-$$OS-$$ARCH;

build_all: test clean build_linux_amd64 build_linux_arm64 build_linux_arm_6 build_linux_arm_7 build_darwin_amd64 build_darwin_arm64 build_windows_amd64
build_all: test clean build_linux_amd64 build_linux_arm64 build_linux_arm_6 build_linux_arm_7 build_darwin_amd64 build_darwin_arm64 build_windows_amd64
23 changes: 16 additions & 7 deletions docker/build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
FROM debian:bookworm-slim
FROM alpine

LABEL org.opencontainers.image.source="https://github.com/vsimakhin/web-logbook" \
org.opencontainers.image.authors="Vladimir Simakhin" \
org.opencontainers.image.title="Web Logbook" \
org.opencontainers.image.description="Container image for Web Logbook https://github.com/vsimakhin/web-logbook"

WORKDIR /web-logbook

RUN apt-get update && \
apt-get install ca-certificates libssl3 openssl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN apk update --no-cache && \
apk add ca-certificates libssl3 openssl && \
adduser -g "WebLogbook" -s /usr/sbin/nologin -D -H weblogbook && \
chown -R weblogbook /web-logbook

ARG TARGETARCH

COPY ./dist/web-logbook-linux-amd64/web-logbook /web-logbook/web-logbook
COPY ./dist/web-logbook-linux-${TARGETARCH}/web-logbook /web-logbook/web-logbook

VOLUME [ "/data", "/certs" ]

EXPOSE 4000

ENTRYPOINT ["./web-logbook", "-dsn", "/data/web-logbook.sql"]
USER weblogbook
ENTRYPOINT ["./web-logbook" ]
CMD ["-dsn", "/data/web-logbook.sql"]
38 changes: 29 additions & 9 deletions docker/release.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
FROM debian:bookworm-slim
# Builder image
FROM alpine AS weblogbookbuilder

WORKDIR /web-logbook

RUN apt-get update && \
apt-get install -y curl jq && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN apk update --no-cache && \
apk add ca-certificates libssl3 openssl curl jq

ARG TARGETARCH

RUN LATEST_RELEASE=$(curl --silent "https://api.github.com/repos/vsimakhin/web-logbook/releases/latest" | \
jq -r '.assets[] | select(.name == "web-logbook-linux-amd64.tar.gz") | .browser_download_url') && \
jq -r ".assets[] | select(.name == \"web-logbook-linux-$TARGETARCH.tar.gz\") | .browser_download_url") && \
curl -L -o web-logbook.tar.gz $LATEST_RELEASE && \
tar -xzf web-logbook.tar.gz && \
cp ./web-logbook-linux-amd64/web-logbook ./ && \
rm -rf web-logbook.tar.gz web-logbook-linux-amd64
cp ./web-logbook-linux-${TARGETARCH}/web-logbook ./ && \
rm -rf web-logbook.tar.gz web-logbook-linux-${TARGETARCH}

# Final image
FROM alpine

LABEL org.opencontainers.image.source="https://github.com/vsimakhin/web-logbook" \
org.opencontainers.image.authors="Vladimir Simakhin" \
org.opencontainers.image.title="Web Logbook" \
org.opencontainers.image.description="Container image for Web Logbook https://github.com/vsimakhin/web-logbook"

WORKDIR /web-logbook

RUN apk update --no-cache && \
apk add ca-certificates libssl3 openssl && \
adduser -g "WebLogbook" -s /usr/sbin/nologin -D -H weblogbook && \
chown -R weblogbook /web-logbook

COPY --from=weblogbookbuilder /web-logbook/web-logbook /web-logbook/web-logbook

VOLUME [ "/data", "/certs" ]

EXPOSE 4000

ENTRYPOINT ["./web-logbook", "-dsn", "/data/web-logbook.sql"]
USER weblogbook
ENTRYPOINT ["./web-logbook" ]
CMD ["-dsn", "/data/web-logbook.sql"]

0 comments on commit bfeb843

Please sign in to comment.