chore: Push the latest image on push master. #1
This file contains 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: Push Docker Image | |
on: | |
workflow_dispatch: { } | |
push: | |
branches: | |
- master | |
env: | |
CI_RUST_TOOLCHAIN: 1.74.0 | |
IMAGE_ID: ghcr.io/xline-kv/xline | |
jobs: | |
push_image: | |
name: Push Docker Image | |
runs-on: ${{ matrix.job.os }} | |
outputs: | |
app_version: ${{ steps.generate_app_version.outputs.app_version }} | |
strategy: | |
fail-fast: false | |
matrix: | |
job: | |
- os: ubuntu-latest | |
platform: linux/amd64 | |
target: x86_64-unknown-linux-gnu | |
cross_image: x86_64-linux-gnu | |
- os: ubuntu-latest | |
platform: linux/arm64 | |
target: aarch64-unknown-linux-gnu | |
cross_image: aarch64-linux-gnu | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Generate App Version | |
id: generate_app_version | |
run: | | |
if [ ${{ github.event_name }} = "push" ];then | |
echo app_version=latest >> $GITHUB_OUTPUT | |
else | |
echo app_version=`git describe --tags --always` >> $GITHUB_OUTPUT | |
fi | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Setup Custom Image for ${{ matrix.job.cross_image }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: ci/cross | |
file: ci/cross/Dockerfile.${{ matrix.job.target }} | |
tags: ${{ matrix.job.cross_image }}:latest | |
load: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Install Toolchain | |
uses: dtolnay/rust-toolchain@v1 | |
with: | |
toolchain: ${{ env.CI_RUST_TOOLCHAIN }} | |
target: ${{ matrix.job.target }} | |
- name: Install cross from binary | |
uses: taiki-e/install-action@cross | |
- name: Build Xline Binary | |
run: | | |
cross build --target ${{ matrix.job.target }} --release | |
# Build docker image across multiple runners | |
- name: Move Cross-compiled Binary | |
run: | | |
mv ./target/${{ matrix.job.target }}/release/xline ./scripts | |
mv ./target/${{ matrix.job.target }}/release/benchmark ./scripts | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: xline-kv | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build Docker Image | |
id: build_image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./scripts | |
platforms: ${{ matrix.job.platform }} | |
outputs: type=image,name=${{ env.IMAGE_ID }},push-by-digest=true,name-canonical=true,push=true | |
- name: Export Digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build_image.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload Digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge_image: | |
needs: push_image | |
uses: ./.github/workflows/merge_image.yml | |
secrets: inherit | |
with: | |
app_version: ${{ needs.push_image.outputs.app_version }} |