Skip to content

Commit e736178

Browse files
committed
Added GitHub Action to build and deploy Docker images to DockerHub
1 parent 8b088dc commit e736178

2 files changed

Lines changed: 124 additions & 0 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Docker Image CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- 'v*'
10+
11+
env:
12+
REGISTRY: docker.io
13+
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
25+
- name: Set up Docker Buildx
26+
id: buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Login to Docker Hub
30+
if: github.event_name != 'pull_request'
31+
uses: docker/login-action@v3
32+
with:
33+
username: ${{ secrets.DOCKERHUB_USERNAME }}
34+
password: ${{ secrets.DOCKERHUB_TOKEN }}
35+
36+
- name: Extract Docker metadata
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
tags: |
42+
type=semver,pattern={{version}},value=${{ inputs.version }}
43+
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.version }}
44+
type=semver,pattern={{major}},value=${{ inputs.version }}
45+
type=raw,value=latest,enable={{is_default_branch}}
46+
flavor: |
47+
latest=false
48+
49+
- name: Build and Push
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: .
53+
platforms: linux/amd64,linux/arm64
54+
push: ${{ github.event_name != 'pull_request' }}
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
###
2+
##: Set up native compile
3+
###
4+
FROM rust:bookworm AS build-native
5+
RUN apt-get update && apt-get install -y ca-certificates openssl sqlite3
6+
RUN echo $(arch)-unknown-linux-gnu > /tmp/rust-target
7+
8+
###
9+
##: Set up arm64 cross compile
10+
###
11+
FROM --platform=$BUILDPLATFORM rust:bookworm AS build-cross-arm64
12+
13+
ARG CC=aarch64-linux-gnu-gcc
14+
ARG CXX=aarch64-linux-gnu-g++
15+
ARG PKG_CONFIG_SYSROOT_DIR=/usr/lib/aarch64-linux-gnu/
16+
ARG CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
17+
18+
RUN dpkg --add-architecture arm64
19+
RUN apt-get update
20+
RUN apt-get install -y g++-aarch64-linux-gnu
21+
RUN apt-get install -y libsqlite3-dev:arm64 libssl-dev:arm64
22+
23+
RUN rustup target add aarch64-unknown-linux-gnu
24+
RUN echo aarch64-unknown-linux-gnu > /tmp/rust-target
25+
26+
###
27+
##: Build targets
28+
###
29+
FROM build-native AS build-arm64-on-arm64
30+
FROM build-native AS build-amd64-on-amd64
31+
FROM build-cross-arm64 AS build-arm64-on-amd64
32+
33+
#####
34+
35+
###
36+
##: Build stage
37+
###
38+
FROM build-$TARGETARCH-on-$BUILDARCH as builder
39+
40+
WORKDIR /opt/helipad
41+
42+
COPY . /opt/helipad
43+
RUN cargo build --release --target=$(cat /tmp/rust-target)
44+
RUN cp ./target/$(cat /tmp/rust-target)/release/helipad .
45+
46+
###
47+
##: Bundle stage
48+
###
49+
FROM --platform=$TARGETPLATFORM debian:bookworm-slim AS runner
50+
51+
RUN apt-get update && \
52+
apt-get install -y ca-certificates openssl sqlite3 && \
53+
rm -fr /var/lib/apt/lists/*
54+
55+
WORKDIR /opt/helipad
56+
57+
COPY --from=builder /opt/helipad/helipad .
58+
COPY --from=builder /opt/helipad/webroot ./webroot
59+
COPY --from=builder /opt/helipad/helipad.conf .
60+
61+
RUN useradd -u 1000 helipad
62+
RUN mkdir /data && chown -R 1000:1000 /data
63+
64+
USER helipad
65+
66+
EXPOSE 2112/tcp
67+
68+
ENTRYPOINT ["/opt/helipad/helipad"]

0 commit comments

Comments
 (0)