build and publish container image #31
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: build and publish container image | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
schedule: | |
# every sunday 3:00 am jst | |
- cron: '0 18 * * 0' | |
env: | |
TARGET_IMAGE: ghcr.io/sarisia/mikanos | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build: | |
strategy: | |
matrix: | |
include: | |
- arch: amd64 | |
- arch: arm64 | |
# turns out macos-14 (m1) runner does not support nested virtualization (docker) | |
# see https://github.com/actions/runner-images/issues/9254#issuecomment-1917916016 | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: arm64 | |
- name: build | |
run: | | |
docker buildx build -t ${{ env.TARGET_IMAGE }}:${{ matrix.arch }} --platform linux/${{ matrix.arch }} ${{ matrix.arch }} && \ | |
docker buildx build -t ${{ env.TARGET_IMAGE }}:vnc-${{ matrix.arch }} --platform linux/${{ matrix.arch }} --build-arg BASE=${{ env.TARGET_IMAGE }}:${{ matrix.arch }} variant/vnc | |
- uses: docker/login-action@v3 | |
# run only when images are pushed | |
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: push | |
# do not push when triggered by push | |
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
run: | | |
docker push ${{ env.TARGET_IMAGE }}:${{ matrix.arch }} && \ | |
docker push ${{ env.TARGET_IMAGE }}:vnc-${{ matrix.arch }} | |
- uses: sarisia/actions-status-discord@v1 | |
if: always() | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
title: ghcr.io/sarisia/mikanos (${{ matrix.arch }}) | |
manifest: | |
runs-on: ubuntu-22.04 | |
needs: build | |
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
steps: | |
- uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: amend manifest | |
run: | | |
docker manifest create ${{ env.TARGET_IMAGE }}:latest \ | |
--amend ${{ env.TARGET_IMAGE }}:arm64 \ | |
--amend ${{ env.TARGET_IMAGE }}:amd64 && \ | |
docker manifest push ${{ env.TARGET_IMAGE }}:latest && \ | |
docker manifest create ${{ env.TARGET_IMAGE }}:vnc \ | |
--amend ${{ env.TARGET_IMAGE }}:vnc-arm64 \ | |
--amend ${{ env.TARGET_IMAGE }}:vnc-amd64 && \ | |
docker manifest push ${{ env.TARGET_IMAGE }}:vnc | |
- uses: sarisia/actions-status-discord@v1 | |
if: always() | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
title: ghcr.io/sarisia/mikanos (amend) |