chore: scaffold project structure (#2) #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build backend | |
on: | |
push: | |
branches: | |
- "main" | |
paths: | |
- ".github/image/Dockerfile" | |
- ".github/workflows/backend.yml" | |
- "backend/**" | |
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: ubuntu-22.04-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 | |
run: cargo build --target ${{ matrix.target }} ${{ matrix.args }} | |
- name: rename binaries | |
run: | | |
mv target/${{ matrix.target }}/release/backend${{ matrix.ext }} backend-${{ matrix.release_for }}${{ matrix.ext }} | |
- name: upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: binaries-backend-${{ matrix.release_for }} | |
path: backend-${{ matrix.release_for }}${{ matrix.ext }} | |
docker: | |
runs-on: ubuntu-latest | |
needs: [build] | |
strategy: | |
matrix: | |
include: | |
- tags: ghcr.io/txpipe/metis-backend,ghcr.io/txpipe/metis-backend:${{ github.sha }} | |
binary: backend | |
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: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
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 | |
# Add docker layer caching to avoid doing extra computation | |
- uses: satackey/[email protected] | |
continue-on-error: true | |
# 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/backend-Linux-x86_64 .github/image/bin/backend-Linux-amd64 | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: .github/image | |
platforms: linux/arm64,linux/amd64 | |
push: true | |
tags: ${{ matrix.tags }} | |
build-args: BIN=${{ matrix.binary }} | |