Skip to content

Publish

Publish #1

Workflow file for this run

name: Publish
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [master]
env:
CARGO_TERM_COLOR: always
DOCKER_REPO: leonardoarcari/dcapal
jobs:
extract-version:
runs-on: ubuntu-22.04
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
metadata: ${{ steps.step_metadata.outputs.metadata }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- id: step_metadata
run: |
cargo metadata --no-deps --format-version=1 > metadata.json
content=`cat metadata.json`
# the following lines are only required for multi line json
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
# end of optional handling for multi line json
echo "metadata=${content}" >> $GITHUB_OUTPUT
build-publish-docker-image:
runs-on: ubuntu-22.04
needs: extract-version
env:
VERSION: ${{ fromJson(needs.extract-version.outputs.metadata).packages[0].version }}
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./dcapal-backend/docker/Dockerfile
push: true
tags: ${{ env.DOCKER_REPO }}:latest,${{ env.DOCKER_REPO }}:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache