Skip to content

Commit b81c5dc

Browse files
committed
chore: github actions for docker hub images
1 parent 3570988 commit b81c5dc

File tree

8 files changed

+224
-51
lines changed

8 files changed

+224
-51
lines changed

.github/workflows/main.yml renamed to .github/workflows/build-and-test.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
name: CI
1+
name: Build, lint and test
22

3-
on:
4-
push:
5-
branches: ['main']
6-
pull_request:
7-
branches: ['*']
3+
on: workflow_call
4+
5+
permissions:
6+
contents: read
87

98
jobs:
109
clippy:
11-
name: Check code formatting
10+
name: Lint
1211
runs-on: ubuntu-latest
1312
steps:
14-
- uses: actions/checkout@v4
15-
- uses: dtolnay/rust-toolchain@stable
16-
with:
17-
components: clippy
18-
- uses: giraffate/clippy-action@v1
19-
with:
20-
reporter: 'github-pr-review'
21-
github_token: ${{ secrets.GITHUB_TOKEN }}
22-
clippy_flags: --all-features --all-targets --color always -- --deny warnings
13+
- uses: actions/checkout@v4
14+
- uses: dtolnay/rust-toolchain@stable
15+
with:
16+
components: clippy
17+
- uses: giraffate/clippy-action@v1
18+
with:
19+
reporter: github-pr-review
20+
github_token: ${{ secrets.GITHUB_TOKEN }}
21+
clippy_flags: --all-features --all-targets --color always -- --deny warnings
2322

2423
build:
2524
name: Build and test
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: ["*"]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: Test
15+
uses: ./.github/workflows/build-and-test.yml
16+
secrets: inherit

.github/workflows/on-tag.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Push docker image
2+
3+
on:
4+
push:
5+
tags:
6+
- v[0-9]+.[0-9]+.[0-9]+*
7+
- "[0-9]+.[0-9]+.[0-9]+*"
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
uses: ./.github/workflows/build-and-test.yml
15+
secrets: inherit
16+
docker-hub-image:
17+
needs: [test]
18+
uses: ./.github/workflows/push-docker-image.yml
19+
secrets: inherit
20+
with:
21+
image_name: bitcoindevproject/simln
22+
artifact_name: simln-docker
23+
dockerfile: ./docker/Dockerfile
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build and push docker image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image_name:
7+
description: Name for the docker image
8+
required: true
9+
type: string
10+
artifact_name:
11+
description: Name for the temporary artifact
12+
required: true
13+
type: string
14+
dockerfile:
15+
description: Path to the dockerfile
16+
required: true
17+
type: string
18+
latest:
19+
description: Whether to tag the image as latest
20+
required: false
21+
type: boolean
22+
default: false
23+
24+
permissions:
25+
contents: read
26+
27+
jobs:
28+
build:
29+
runs-on: ubuntu-latest
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
platform:
34+
- linux/amd64
35+
# - linux/arm/v6
36+
# - linux/arm/v7
37+
- linux/arm64
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v3
41+
- name: Docker meta
42+
id: meta
43+
uses: docker/metadata-action@v4
44+
with:
45+
images: ${{ inputs.image_name }}
46+
- name: Set up QEMU
47+
uses: docker/setup-qemu-action@v3
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v2
50+
- name: Login to Docker Hub
51+
uses: docker/login-action@v2
52+
with:
53+
username: ${{ secrets.DOCKERHUB_USERNAME }}
54+
password: ${{ secrets.DOCKERHUB_TOKEN }}
55+
- name: Build and push by digest
56+
id: build
57+
uses: docker/build-push-action@v4
58+
with:
59+
context: .
60+
file: ${{ inputs.dockerfile}}
61+
platforms: ${{ matrix.platform }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
outputs: type=image,name=${{ inputs.image_name }},push-by-digest=true,name-canonical=true,push=true
64+
- name: Export digest
65+
run: |
66+
mkdir -p /tmp/digests
67+
digest="${{ steps.build.outputs.digest }}"
68+
touch "/tmp/digests/${digest#sha256:}"
69+
- name: Upload digest
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: digests${{ inputs.artifact_name }}
73+
path: /tmp/digests/*
74+
if-no-files-found: error
75+
retention-days: 1
76+
77+
merge:
78+
runs-on: ubuntu-latest
79+
needs:
80+
- build
81+
steps:
82+
- name: Download digests
83+
uses: actions/download-artifact@v3
84+
with:
85+
name: digests${{ inputs.artifact_name }}
86+
path: /tmp/digests
87+
- name: Set up Docker Buildx
88+
uses: docker/setup-buildx-action@v2
89+
- name: Docker meta
90+
id: meta
91+
uses: docker/metadata-action@v4
92+
with:
93+
images: ${{ inputs.image_name }}
94+
flavor: |
95+
latest=${{ inputs.latest && 'true' || 'false' }}
96+
tags: |
97+
type=semver,pattern={{version}}
98+
- name: Login to Docker Hub
99+
uses: docker/login-action@v2
100+
with:
101+
username: ${{ secrets.DOCKERHUB_USERNAME }}
102+
password: ${{ secrets.DOCKERHUB_TOKEN }}
103+
- name: Create manifest list and push
104+
working-directory: /tmp/digests
105+
run: |
106+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
107+
$(printf '${{ inputs.image_name }}@sha256:%s ' *)
108+
- name: Inspect image
109+
run: |
110+
docker buildx imagetools inspect ${{ inputs.image_name }}:${{ steps.meta.outputs.version }}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Push latest tag to docker hub
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
required: true
8+
description: Docker tag to set as latest
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
DOCKER_IMAGE: bitcoindevproject/simln
15+
16+
jobs:
17+
update-docker-images-to-latest:
18+
name: Update docker images to latest
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions-ecosystem/action-regex-match@v2
22+
id: regex-match
23+
with:
24+
text: ${{ inputs.tag }}
25+
regex: v?(.+)
26+
- name: Login to Docker Hub
27+
uses: docker/login-action@v2
28+
with:
29+
username: ${{ secrets.DOCKERHUB_USERNAME }}
30+
password: ${{ secrets.DOCKERHUB_TOKEN }}
31+
- name: Docker tag and push latest
32+
run: |
33+
docker buildx imagetools create -t ${{ env.DOCKER_IMAGE }}:latest ${{ env.DOCKER_IMAGE }}:${{ steps.regex-match.outputs.group1 }}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
LOG_LEVEL ?= info
22

33
build-docker:
4-
chmod +x ./docker/build.sh && ./docker/build.sh
4+
docker build -f docker/Dockerfile -t sim-ln .
55

66
mount-volume:
77
chmod +x ./docker/setup-volume.sh && ./docker/setup-volume.sh "$(SIMFILE_PATH)"
@@ -28,4 +28,4 @@ run-interactive:
2828
docker run --rm --name sim-ln --init -v simln-data:/data -e SIMFILE_PATH=/data/sim.json -it sim-ln
2929

3030
stop-docker:
31-
docker stop sim-ln
31+
docker stop sim-ln

docker/Dockerfile

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
1-
# Use the rust image as the base image for the build stage
2-
FROM rust:latest AS builder
3-
4-
# Receive architecture as an argument
5-
ARG TARGET_ARCH
1+
# Run from the root of the project
62

3+
# Use the rust image as the base image for the build stage
4+
FROM rust:latest AS base
5+
# buildkit will provide this automatically, no need to pass it in
6+
ARG TARGETARCH
7+
8+
FROM base as builder-amd64
9+
ENV TARGET_RUST_ARCH="x86_64-unknown-linux-musl"
10+
11+
FROM base as builder-arm64
12+
ENV TARGET_RUST_ARCH="aarch64-unknown-linux-musl"
13+
RUN apt-get update && apt-get install clang llvm -y --no-install-recommends
14+
ENV CC_aarch64_unknown_linux_musl=clang
15+
ENV AR_aarch64_unknown_linux_musl=llvm-ar
16+
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"
17+
18+
FROM builder-${TARGETARCH} as builder
19+
RUN echo "Building for architecture: $TARGET_RUST_ARCH"
720
# Copy the source code
8-
COPY . /tmp/sim-ln
21+
COPY . /sim-ln
922

1023
# Install the dependencies required for building sim-ln
1124
RUN apt-get update \
1225
&& apt-get -y --no-install-recommends install protobuf-compiler musl-tools
1326

14-
RUN cd /tmp/sim-ln \
15-
&& rustup target add ${TARGET_ARCH} \
16-
&& rustup component add rustfmt \
17-
&& RUSTFLAGS='-C target-feature=+crt-static' cargo build --locked --release --target=${TARGET_ARCH}
27+
RUN rustup target add ${TARGET_RUST_ARCH}
28+
RUN rustup component add rustfmt
29+
RUN cd /sim-ln && RUSTFLAGS='-C target-feature=+crt-static' cargo build --locked --release --target=${TARGET_RUST_ARCH}
30+
RUN mv /sim-ln/target/${TARGET_RUST_ARCH}/release/sim-cli /sim-ln/sim-cli
1831

1932
# Use a new stage with a smaller base image to reduce image size
2033
FROM alpine:latest
2134

22-
ARG TARGET_ARCH
23-
2435
RUN apk update && apk upgrade
2536

2637
# Copy the sim-cli binaries from the build stage to the new stage
27-
COPY --from=builder /tmp/sim-ln/target/${TARGET_ARCH}/release/sim-cli /usr/local/bin/
38+
COPY --from=builder /sim-ln/sim-cli /usr/local/bin/
2839

2940
# Copy the entrypoint script to the container
3041
COPY docker/entrypoint.sh /entrypoint.sh
3142

3243
RUN chmod +x entrypoint.sh
3344

34-
ENTRYPOINT [ "/entrypoint.sh" ]
45+
ENTRYPOINT [ "/entrypoint.sh" ]

docker/build.sh

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

0 commit comments

Comments
 (0)