Update image when Dockerfile is changed #50
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: "Update image when Dockerfile is changed" | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'Dockerfile' | |
workflow_dispatch: | |
jobs: | |
rebuild-container: | |
name: "Rebuild Container with the latest base image" | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Prepare outputs | |
id: prep | |
run: | | |
echo "::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | |
- | |
name: Set up QEMU | |
uses: docker/[email protected] | |
with: | |
platforms: linux/arm64 | |
- | |
name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- | |
name: Login to GitHub Container Registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Login to DockerHub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- | |
name: Checkout repository | |
uses: actions/checkout@v4 | |
- | |
name: Get Monero Release Tag | |
id: get_tag | |
run: echo "::set-output name=tag::$(awk -F '=' '/MONERO_BRANCH=/ {print $2}' Dockerfile)" | |
- | |
name: Build x86_64 image | |
id: docker_build_amd64 | |
uses: docker/[email protected] | |
with: | |
push: false | |
load: true | |
platforms: linux/amd64 | |
tags: simple-monerod:alpine-amd64 | |
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/simple-monerod:latest | |
cache-to: type=inline | |
- | |
name: Test-run x86_64 image | |
run: | | |
docker run --rm simple-monerod:alpine-amd64 & | |
PID=$! | |
sleep 30 | |
kill -SIGINT $PID # this will return a non-zero exit code if the container dies early on | |
- | |
name: Build and push to Docker Hub and GitHub Packages Docker Registry | |
uses: docker/[email protected] | |
id: docker_build_push | |
with: | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/simple-monerod:latest | |
ghcr.io/${{ github.repository_owner }}/simple-monerod:${{ steps.get_tag.outputs.tag }} | |
${{ secrets.DOCKER_USERNAME }}/simple-monerod:latest | |
${{ secrets.DOCKER_USERNAME }}/simple-monerod:${{ steps.get_tag.outputs.tag }} | |
labels: | | |
org.opencontainers.image.source=${{ github.event.repository.html_url }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/simple-monerod:latest | |
cache-to: type=inline |