Skip to content

Commit 25da59e

Browse files
committed
chore: optimize the build speed of docker
1 parent 70f10bd commit 25da59e

4 files changed

Lines changed: 56 additions & 45 deletions

File tree

.github/workflows/build-docker-image.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/workflows/build-release.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ on:
55
- v*
66

77
env:
8+
IMAGE_NAME: dyndns
89
CARGO_TERM_COLOR: always
10+
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
911

1012
jobs:
1113
build-cross:
1214
runs-on: ubuntu-latest
1315
env:
1416
RUST_BACKTRACE: full
15-
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
1617
strategy:
1718
matrix:
1819
target:
@@ -35,14 +36,41 @@ jobs:
3536
timeout-minutes: 120
3637
run: |
3738
cross build --release --target ${{ matrix.target }} &&
38-
mv target/${{ matrix.target }}/release/dyndns target/${{ matrix.target }}/release/dyndns-${{ matrix.target }}
39+
cp target/${{ matrix.target }}/release/dyndns target/${{ matrix.target }}/release/dyndns-${{ matrix.target }}
3940
- name: Upload Github Assets
4041
uses: softprops/action-gh-release@v1
4142
env:
4243
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4344
with:
4445
files: target/${{ matrix.target }}/release/dyndns-${{ matrix.target }}
4546
prerelease: ${{ contains(github.ref, '-') }}
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v2
49+
- name: Setup Docker Buildx
50+
uses: docker/setup-buildx-action@v1
51+
- name: Login to GitHub Container Registry
52+
uses: docker/login-action@v2
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.repository_owner }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
- name: Generate App Version
58+
run: echo VERSIONED_TAG=`git describe --tags --always` >> $GITHUB_ENV
59+
- name: set lower case owner name
60+
run: |
61+
echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV}
62+
env:
63+
OWNER: "${{ github.repository_owner }}"
64+
- name: Build and release Docker images
65+
uses: docker/build-push-action@v3
66+
with:
67+
file: Dockerfile.action
68+
build-args: "DOWNLOAD_BASE=https://github.com/${{ github.repository }}/releases/download/${{ env.VERSIONED_TAG }}"
69+
platforms: linux/amd64,linux/arm64,linux/arm/v7
70+
tags: |
71+
ghcr.io/${{ env.OWNER_LC }}/${{ env.IMAGE_NAME }}:latest
72+
ghcr.io/${{ env.OWNER_LC }}/${{ env.IMAGE_NAME }}:${{ env.VERSIONED_TAG }}
73+
push: true
4674

4775
build-unix:
4876
runs-on: ${{ matrix.os }}

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM ghcr.io/kotahv/dyndns-vue:latest as dyndns-vue
22

33
FROM rust:1.68-alpine as builder
44

5-
RUN apk add --no-cache musl-dev pkgconfig openssl libressl-dev
5+
RUN apk add --no-cache musl-dev
66

77
RUN cargo new --bin /app
88
WORKDIR /app
@@ -17,8 +17,6 @@ RUN CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse cargo build --release
1717

1818
FROM alpine:latest
1919

20-
RUN apk add --no-cache openssl
21-
2220
ENV DYNDNS_ADDR=0.0.0.0:80 DYNDNS_DEBUG=false DYNDNS_WEB_DIR=/dyndns-vue DYNDNS_DATABASE_URL=/dyndns/data/dyndns.db
2321

2422
VOLUME /dyndns/data
@@ -30,4 +28,4 @@ COPY --from=dyndns-vue /dyndns-vue /dyndns-vue
3028

3129
COPY docker/start.sh /start.sh
3230

33-
CMD [ "/start.sh" ]
31+
CMD [ "/start.sh" ]

Dockerfile.action

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM ghcr.io/kotahv/dyndns-vue:latest as dyndns-vue
2+
3+
FROM alpine:latest as builder
4+
5+
ARG DOWNLOAD_BASE
6+
RUN ARCH=$(uname -m | sed -e "s/armv7l/armv7-unknown-linux-musleabihf/g" | sed -e "s/aarch64/aarch64-unknown-linux-musl/g" | sed -e "s/x86_64/x86_64-unknown-linux-musl/g") && \
7+
apk add --no-cache curl && \
8+
curl -L "${DOWNLOAD_BASE}/dyndns-${ARCH}" -o /dyndns && \
9+
chmod +x /dyndns
10+
11+
FROM alpine:latest
12+
13+
ENV DYNDNS_ADDR=0.0.0.0:80 DYNDNS_DEBUG=false DYNDNS_WEB_DIR=/dyndns-vue DYNDNS_DATABASE_URL=/dyndns/data/dyndns.db
14+
15+
VOLUME /dyndns/data
16+
EXPOSE 80
17+
18+
WORKDIR /dyndns
19+
COPY --from=builder /dyndns .
20+
COPY --from=dyndns-vue /dyndns-vue /dyndns-vue
21+
22+
COPY docker/start.sh /start.sh
23+
24+
CMD [ "/start.sh" ]

0 commit comments

Comments
 (0)