Skip to content

Docker

Docker #404

name: Docker
on:
push:
branches: [ "master" ]
tags: [ "v**" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '0 14 * * *'
env:
SHOULD_PUSH: ${{ github.event_name != 'pull_request' && (github.ref_type == 'tag' || github.ref == 'refs/heads/dev') }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
strategy:
matrix:
app:
- daemon
- miner
- wallet
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: xelis
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Retrieve version from Cargo.toml
run: |
VERSION=`awk -F ' = ' '$1 ~ /version/ { gsub(/[\\"]/, "", $2); printf("%s",$2) }' xelis_${{ matrix.app }}/Cargo.toml`
echo "XELIS_VERSION=${VERSION}" >> "$GITHUB_ENV"
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: xelis/${{ matrix.app }}
labels: |
org.opencontainers.image.title=Xelis ${{ matrix.app }}
tags: |
type=schedule,pattern=${{ env.XELIS_VERSION }}-nightly-{{date 'YYYYMMDD'}}
type=semver,pattern={{version}},event=tag
type=ref,event=pr
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ env.SHOULD_PUSH }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: ${{ env.SHOULD_PUSH && 'type=gha,mode=max' || '' }}
build-args: |
app=xelis_${{ matrix.app }}
commit_hash=${{ github.sha }}
platforms: ${{ env.SHOULD_PUSH && 'linux/amd64,linux/arm64' || 'linux/amd64' }}