Skip to content

Commit

Permalink
Merge pull request #264 from vsimakhin/feature/update-docker-image
Browse files Browse the repository at this point in the history
docker multiarch image
  • Loading branch information
vsimakhin authored Nov 10, 2024
2 parents bf64391 + 0256a27 commit 6b3cecc
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 33 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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [Unreleased]

- Update: There are few major updates for the docker files and image containers
- The base image changed from `debian:bookworm-slim` to `alpine`, which reduced the container image size 3x - from 104MB to 37MB
- The image supports `linux/amd64` and `linux/arm64` now
- The entrypoint and cmd are changed. If you don't see data with the new image try to remove `./web-logbook` from the command
```yaml
# old image
ENTRYPOINT ["./web-logbook", "-dsn", "/data/web-logbook.sql"]

# new image
ENTRYPOINT ["./web-logbook" ]
CMD ["-dsn", "/data/web-logbook.sql"]
```

## [2.43.3] - 04.11.2024

- Fix: Resolved SQL syntax error that occurred when creating a new license record.
Expand Down
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ You also can easily export all flight records into EASA style pdf format, print

# Changelog

## [Unreleased]

- Update: There are few major updates for the docker files and image containers
- The base image changed from `debian:bookworm-slim` to `alpine`, which reduced the container image size 3x - from 104MB to 37MB
- The image supports `linux/amd64` and `linux/arm64` now
- The entrypoint and cmd are changed. If you don't see data with the new image try to remove `./web-logbook` from the command
```yaml
# old image
ENTRYPOINT ["./web-logbook", "-dsn", "/data/web-logbook.sql"]

# new image
ENTRYPOINT ["./web-logbook" ]
CMD ["-dsn", "/data/web-logbook.sql"]
```

## [2.43.3] - 04.11.2024

- Fix: Resolved SQL syntax error that occurred when creating a new license record.
Expand Down
20 changes: 13 additions & 7 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Docker

There are several options for how you can use the dockerized version of the web-logbook application. The provided examples are for amd64 architecture, but you can build your own docker image and for any platform, using the Dockerfile examples below.
There are several options for how you can use the dockerized version of the web-logbook application.

# Images

## Docker Hub

There is an official public repository at the Docker Hub [https://hub.docker.com/repository/docker/vsimakhin/web-logbook/](https://hub.docker.com/repository/docker/vsimakhin/web-logbook/) where you can pull the image. You can pull either the `latest` tag or a tag according to the release version.
There is an official public repository at the Docker Hub [https://hub.docker.com/repository/docker/vsimakhin/web-logbook/](https://hub.docker.com/repository/docker/vsimakhin/web-logbook/) where you can pull the image for `amd64` or `arm64` platforms. You can pull either the `latest` tag or a tag according to the release version.

```bash
docker pull vsimakhin/web-logbook:latest
Expand All @@ -20,6 +20,8 @@ To build a docker image from the latest published release you can use [release.D
docker build -t vsimakhin/web-logbook:latest -f $PWD/docker/release.Dockerfile .
```

If you build locally you can use any container image name instead of `vsimakhin/web-logbook:latest`, for example `my-logbook:latest`.

## Build image from build files

To build a docker image from the compiled binaries you can use [build.Dockerfile](./build.Dockerfile)
Expand All @@ -29,31 +31,35 @@ To build a docker image from the compiled binaries you can use [build.Dockerfile
make build_all
# build docker image
docker build -t vsimakhin/web-logbook:latest -f $PWD/docker/build.Dockerfile .

```

# Run container


By default the dockerized app will create an sqlite database in `/data/` directory. So the recommended way to run the container is to mount a volume with database

```bash
docker run --rm -it -p 4000:4000 -v /YOUR/FULL/PATH/WITH/DATABASE:/data vsimakhin/web-logbook:latest
```
So once you run the container it will create a `web-logbook.sql` file with all data at `/YOUR/FULL/PATH/WITH/DATABASE/web-logbook.sql`

It is also possible to override the standard entry point and set your own additional options, like cert for SSL and etc
The standard entrypoint and cmd for the container image is
```bash
ENTRYPOINT ["./web-logbook" ]
CMD ["-dsn", "/data/web-logbook.sql"]
```

You may override it and set additional options like cert for SSL and etc

```bash
docker run --rm -it -p 4000:4000 -v /YOUR/FULL/PATH/WITH/DATABASE:/data -v /PATH/TO/CERTS:/certs vsimakhin/web-logbook:latest ./web-logbook -dsn /data/web-logbook.sql -cert /certs/my-certificate.pem
docker run --rm -it -p 4000:4000 -v /YOUR/FULL/PATH/WITH/DATABASE:/data -v /PATH/TO/CERTS:/certs vsimakhin/web-logbook:latest -dsn /data/web-logbook.sql -cert /certs/my-certificate.pem -env dev
```

You may use docker-compose to run the container
```yaml
services:
web-logbook:
image: vsimakhin/web-logbook:latest
command: ./web-logbook -dsn /data/web-logbook.sql
command: -dsn /data/web-logbook.sql
ports:
- 4000:4000
volumes:
Expand Down
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 6b3cecc

Please sign in to comment.