Skip to content

Commit bef2f53

Browse files
authored
Split Docker build into its own workflow (#3602)
1 parent 8894314 commit bef2f53

File tree

4 files changed

+136
-124
lines changed

4 files changed

+136
-124
lines changed

.dockerignore

+10-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
target/
1+
/.changelog/
2+
/.git/
3+
/.gitignore
4+
/.github
5+
/ci/
6+
/docs/
7+
/e2e/
8+
/guide/
9+
/scripts/
10+
/target/

.github/workflows/docker.yml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Build Hermes Docker image, push to Docker Hub and GHCR.io.
2+
3+
name: Docker
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
tags:
9+
- v[0-9]+.*
10+
11+
env:
12+
REGISTRY_IMAGE: informalsystems/hermes
13+
14+
jobs:
15+
docker-build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
platform:
21+
- linux/amd64
22+
- linux/arm64
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Docker meta
28+
id: meta
29+
uses: docker/metadata-action@v4
30+
with:
31+
images: ${{ env.REGISTRY_IMAGE }}
32+
33+
- name: Set up QEMU
34+
uses: docker/setup-qemu-action@v2
35+
36+
- name: Set up Docker Buildx
37+
id: buildx
38+
uses: docker/setup-buildx-action@v2
39+
40+
- name: Login to Docker Hub
41+
uses: docker/login-action@v2
42+
with:
43+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
44+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
45+
46+
- name: Build and push by digest
47+
id: build
48+
uses: docker/build-push-action@v4
49+
with:
50+
context: .
51+
file: ./ci/release/hermes.Dockerfile
52+
platforms: ${{ matrix.platform }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
55+
cache-from: type=gha
56+
cache-to: type=gha,mode=max
57+
58+
- name: Export digest
59+
run: |
60+
mkdir -p /tmp/digests
61+
digest="${{ steps.build.outputs.digest }}"
62+
touch "/tmp/digests/${digest#sha256:}"
63+
64+
- name: Upload digest
65+
uses: actions/upload-artifact@v3
66+
with:
67+
name: digests
68+
path: /tmp/digests/*
69+
if-no-files-found: error
70+
retention-days: 1
71+
72+
docker-merge:
73+
runs-on: ubuntu-latest
74+
needs:
75+
- docker-build
76+
steps:
77+
- name: Download digests
78+
uses: actions/download-artifact@v3
79+
with:
80+
name: digests
81+
path: /tmp/digests
82+
83+
- name: Set up Docker Buildx
84+
uses: docker/setup-buildx-action@v2
85+
86+
- name: Docker meta
87+
id: meta
88+
uses: docker/metadata-action@v4
89+
with:
90+
images: ${{ env.REGISTRY_IMAGE }}
91+
92+
- name: Login to Docker Hub
93+
uses: docker/login-action@v2
94+
with:
95+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
96+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
97+
98+
- name: Create manifest list and push
99+
working-directory: /tmp/digests
100+
run: |
101+
docker buildx imagetools create --tag ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \
102+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
103+
104+
- name: Inspect image
105+
run: |
106+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
107+
108+
- name: Login to GitHub Container Registry
109+
uses: docker/login-action@v2
110+
with:
111+
registry: ghcr.io
112+
username: ${{ github.repository_owner }}
113+
password: ${{ secrets.GITHUB_TOKEN }}
114+
115+
- name: Push image to GHCR
116+
run: |
117+
docker buildx imagetools create \
118+
--tag ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \
119+
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

.github/workflows/release.yml

+1-115
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Uploads Hermes binary.
2-
# Ref: https://github.com/marketplace/actions/build-and-upload-rust-binary-to-github-releases
1+
# Create GitHub release and upload Hermes binaries.
32

43
name: Release
54

@@ -8,9 +7,6 @@ on:
87
tags:
98
- v[0-9]+.*
109

11-
env:
12-
REGISTRY_IMAGE: informalsystems/hermes
13-
1410
jobs:
1511
create-release:
1612
runs-on: ubuntu-latest
@@ -62,113 +58,3 @@ jobs:
6258
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6359
# (optional)
6460
CARGO_PROFILE_RELEASE_LTO: true
65-
66-
docker-build:
67-
runs-on: ubuntu-latest
68-
strategy:
69-
fail-fast: false
70-
matrix:
71-
platform:
72-
- linux/amd64
73-
- linux/arm64
74-
steps:
75-
- name: Checkout
76-
uses: actions/checkout@v4
77-
78-
- name: Docker meta
79-
id: meta
80-
uses: docker/metadata-action@v4
81-
with:
82-
images: ${{ env.REGISTRY_IMAGE }}
83-
84-
- name: Set up QEMU
85-
uses: docker/setup-qemu-action@v2
86-
87-
- name: Set up Docker Buildx
88-
id: buildx
89-
uses: docker/setup-buildx-action@v2
90-
91-
- name: Login to Docker Hub
92-
uses: docker/login-action@v2
93-
with:
94-
username: ${{ secrets.DOCKER_HUB_USERNAME }}
95-
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
96-
97-
- name: Get release version
98-
run: echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
99-
100-
- name: Build and push by digest
101-
id: build
102-
uses: docker/build-push-action@v4
103-
with:
104-
context: ./ci/release/
105-
file: ./ci/release/hermes.Dockerfile
106-
build-args: TAG=v${{env.TAG}}
107-
platforms: ${{ matrix.platform }}
108-
labels: ${{ steps.meta.outputs.labels }}
109-
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
110-
cache-from: type=gha
111-
cache-to: type=gha,mode=max
112-
113-
- name: Export digest
114-
run: |
115-
mkdir -p /tmp/digests
116-
digest="${{ steps.build.outputs.digest }}"
117-
touch "/tmp/digests/${digest#sha256:}"
118-
119-
- name: Upload digest
120-
uses: actions/upload-artifact@v3
121-
with:
122-
name: digests
123-
path: /tmp/digests/*
124-
if-no-files-found: error
125-
retention-days: 1
126-
127-
docker-merge:
128-
runs-on: ubuntu-latest
129-
needs:
130-
- docker-build
131-
steps:
132-
- name: Download digests
133-
uses: actions/download-artifact@v3
134-
with:
135-
name: digests
136-
path: /tmp/digests
137-
138-
- name: Set up Docker Buildx
139-
uses: docker/setup-buildx-action@v2
140-
141-
- name: Docker meta
142-
id: meta
143-
uses: docker/metadata-action@v4
144-
with:
145-
images: ${{ env.REGISTRY_IMAGE }}
146-
147-
- name: Login to Docker Hub
148-
uses: docker/login-action@v2
149-
with:
150-
username: ${{ secrets.DOCKER_HUB_USERNAME }}
151-
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
152-
153-
- name: Create manifest list and push
154-
working-directory: /tmp/digests
155-
run: |
156-
docker buildx imagetools create --tag ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \
157-
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
158-
159-
- name: Inspect image
160-
run: |
161-
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
162-
163-
- name: Login to GitHub Container Registry
164-
uses: docker/login-action@v2
165-
with:
166-
registry: ghcr.io
167-
username: ${{ github.repository_owner }}
168-
password: ${{ secrets.GITHUB_TOKEN }}
169-
170-
- name: Push image to GHCR
171-
run: |
172-
docker buildx imagetools create \
173-
--tag ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \
174-
${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

ci/release/hermes.Dockerfile

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1+
# Used for running Hermes in Docker containers
12
#
2-
# Used for running hermes in docker containers
3-
#
4-
# Usage:
5-
# docker build . --build-arg TAG=v0.3.0 -t informalsystems/hermes:0.3.0 -f hermes.Dockerfile
3+
# Usage: (from the root of the working copy)
4+
# $ docker build . -t informalsystems/hermes -f ci/release/hermes.Dockerfile
65

76
FROM rust:1-buster AS build-env
87

98
ARG TAG
109

1110
WORKDIR /root
1211

13-
RUN git clone -b ${TAG} --depth 1 https://github.com/informalsystems/hermes \
14-
&& cd hermes \
15-
&& cargo build --release
12+
COPY . .
13+
RUN cargo build --release
1614

1715
FROM ubuntu:latest
1816
LABEL maintainer="[email protected]"
@@ -27,4 +25,4 @@ WORKDIR /home/hermes
2725
USER hermes:hermes
2826
ENTRYPOINT ["/usr/bin/hermes"]
2927

30-
COPY --chown=0:0 --from=build-env /root/hermes/target/release/hermes /usr/bin/hermes
28+
COPY --chown=hermes:hermes --from=build-env /root/target/release/hermes /usr/bin/hermes

0 commit comments

Comments
 (0)