Skip to content

Commit

Permalink
ci: implement docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Feb 17, 2025
1 parent dd56cd0 commit 65b7fb2
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM debian:12-slim

RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

COPY genesis /etc/genesis

ARG TARGETARCH
COPY bin/baliusd-Linux-${TARGETARCH} /bin/baliusd
RUN chmod +x /bin/baliusd
RUN ln -s /bin/baliusd /baliusd

ENTRYPOINT [ "baliusd" ]
113 changes: 113 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Docker
on:
push:
branches:
- "main"
tags:
- "v*"

jobs:
build:
continue-on-error: true

strategy:
matrix:
include:
- release_for: Linux-x86_64
build_on: ubuntu-22.04
target: x86_64-unknown-linux-gnu
args: "--locked --release"

- release_for: Linux-arm64
build_on: buildjet-2vcpu-ubuntu-2204-arm
target: "aarch64-unknown-linux-gnu"
args: "--locked --release"

runs-on: ${{ matrix.build_on }}

steps:
- name: checkout repository
uses: actions/checkout@v4

- uses: Swatinem/rust-cache@v2
with:
shared-key: "release"

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Run cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.target }} ${{ matrix.args }}

- name: rename binaries
run: |
mv target/${{ matrix.target }}/release/baliusd${{ matrix.ext }} baliusd-${{ matrix.release_for }}${{ matrix.ext }}
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.release_for }}
path: baliusd-${{ matrix.release_for }}${{ matrix.ext }}

docker:
runs-on: ubuntu-latest
needs: [build]

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/txpipe/baliusd
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern=v{{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern=v{{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern=v{{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=sha
- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: ghcr.io/txpipe
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: binaries-*
merge-multiple: true
path: .github/image/bin

# we need to rename the artifact so that the name matches
# the value that Docker uses for TARGET_ARCH to keep the
# Dockerfile simple
- name: Rename artifacts
run: |+
mv .github/image/bin/baliusd-Linux-x86_64 .github/image/bin/baliusd-Linux-amd64
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .github/image
platforms: linux/arm64,linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 65b7fb2

Please sign in to comment.