Docker #10
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
# https://codingpackets.com/blog/rust-binary-and-docker-releases-using-github-actions/#release-workflow | |
# https://twitter.com/mjovanc/article/1757733086236643419 | |
# https://cjwebb.com/rust-github-actions-on-arm/ | |
name: Docker | |
on: | |
# this code should exist on the 'master' or 'main' branch | |
# https://github.com/orgs/community/discussions/25288#discussioncomment-3247293 | |
workflow_run: | |
workflows: [ "Test" ] | |
types: | |
- "completed" | |
branches: | |
- master | |
- dev | |
- 'release/**' | |
env: | |
GITHUB_REGISTRY: ghcr.io | |
IMAGE_NAME: ghcr.io/${{ github.repository }} | |
APT_DEPENDENCIES: "['libasound2-dev']" | |
jobs: | |
get-env-vars: | |
name: Get Environment vars | |
runs-on: ubuntu-latest | |
outputs: | |
APT_DEPENDENCIES: ${{ env.APT_DEPENDENCIES }} | |
steps: | |
- run: echo "null" | |
create-release: | |
name: Create Release | |
runs-on: ubuntu-latest | |
needs: [ get-env-vars ] | |
permissions: | |
contents: read | |
packages: write | |
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v2 | |
with: | |
submodules: recursive | |
- name: Get abbreviated SHA hash of the commit | |
uses: benjlevesque/short-sha@v2.2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.GITHUB_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
profile: minimal | |
override: true | |
- name: Install deps | |
if: ${{ fromJSON(needs.get-env-vars.outputs.APT_DEPENDENCIES)[0] != null }} | |
run: sudo apt-get -y install ${{ join(fromJSON(needs.get-env-vars.outputs.APT_DEPENDENCIES), ' ') }} | |
- name: Build release artifact | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: --release --timings --workspace --examples | |
- name: Save build timings | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release build timings | |
path: target/cargo-timings/cargo-timing.html | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:latest | |
${{ env.IMAGE_NAME }}:${{ env.SHA }} |