Skip to content

Commit dd69255

Browse files
Add ability to build Docker image with prebuilt binary from GH Releases + Pass PREBUILT_TAG in GH Action workflow
1 parent f8570c4 commit dd69255

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ jobs:
99
build-releases:
1010
runs-on: ubuntu-latest
1111

12+
outputs:
13+
tag: ${{ steps.current_tag.outputs.tag }}
14+
1215
steps:
1316
- name: Checkout code
1417
uses: actions/checkout@v2
@@ -77,6 +80,7 @@ jobs:
7780
token: ${{ secrets.PACKAGECLOUD_TOKEN }}
7881

7982
build-docker:
83+
needs: build-releases
8084
runs-on: ubuntu-latest
8185

8286
steps:
@@ -108,6 +112,8 @@ jobs:
108112
tags: ${{ steps.metadata.outputs.tags }}
109113
labels: ${{ steps.metadata.outputs.labels }}
110114
push: true
115+
build-args: |
116+
PREBUILT_TAG=${{ needs.build-releases.outputs.tag }}
111117
platforms: |
112118
linux/amd64
113119
linux/arm64

Dockerfile

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
FROM rust:latest AS build
22

3+
ARG PREBUILT_TAG
34
ARG TARGETPLATFORM
45

6+
ENV PREBUILT_TAG=$PREBUILT_TAG
7+
58
WORKDIR /app
69
COPY . /app
710

811
RUN case ${TARGETPLATFORM} in \
9-
"linux/amd64") echo "x86_64-unknown-linux-musl" > .toolchain ;; \
10-
"linux/arm64") echo "aarch64-unknown-linux-musl" > .toolchain ;; \
12+
"linux/amd64") echo "x86_64" > .arch && echo "x86_64-unknown-linux-musl" > .toolchain ;; \
13+
"linux/arm64") echo "aarch64" > .arch && echo "aarch64-unknown-linux-musl" > .toolchain ;; \
1114
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
1215
esac
1316

14-
RUN apt-get update
15-
RUN apt-get install -y musl-tools
16-
17-
RUN rustup target add $(cat .toolchain)
18-
19-
RUN cargo build --release --target $(cat .toolchain)
20-
RUN mv ./target/$(cat .toolchain)/release/vigil ./
17+
# Run full build?
18+
RUN if [ -z "$PREBUILT_TAG" ]; then \
19+
apt-get update && \
20+
apt-get install -y musl-tools && \
21+
rustup target add $(cat .toolchain) \
22+
; fi
23+
RUN if [ -z "$PREBUILT_TAG" ]; then \
24+
cargo build --release --target $(cat .toolchain) && \
25+
mkdir -p ./vigil/ && \
26+
mv ./target/$(cat .toolchain)/release/vigil ./vigil/ \
27+
; fi
28+
29+
# Pull pre-built binary?
30+
RUN if [ ! -z "$PREBUILT_TAG" ]; then \
31+
wget https://github.com/valeriansaliou/vigil/releases/download/$PREBUILT_TAG/$PREBUILT_TAG-$(cat .arch).tar.gz && \
32+
tar -xzf $PREBUILT_TAG-$(cat .arch).tar.gz \
33+
; fi
2134

2235
FROM alpine:latest
2336

2437
WORKDIR /usr/src/vigil
2538

26-
COPY ./res/assets/ ./res/assets/
2739
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
28-
COPY --from=build /app/vigil /usr/local/bin/vigil
40+
COPY --from=build /app/vigil/vigil /usr/local/bin/vigil
41+
COPY --from=build /app/vigil/res/assets/ ./res/assets/
2942

3043
CMD [ "vigil", "-c", "/etc/vigil.cfg" ]
3144

0 commit comments

Comments
 (0)