docker: Build and test localnet on macOS #568
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: docker-localnet | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
docker: | |
strategy: | |
matrix: | |
docker_image: [sapphire-localnet] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
# We need history to determine oasis-web3-gateway version from git tag. | |
fetch-depth: 0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Compute version | |
# Version docker image by date and git revision. | |
run: | | |
echo "VERSION=$(date +%Y-%m-%d-git$(git rev-parse --short HEAD))" >> $GITHUB_ENV | |
- name: Build | |
uses: docker/build-push-action@v6 | |
with: | |
build-args: | | |
VERSION=${{ env.VERSION }} | |
context: . | |
file: docker/${{ matrix.docker_image }}/Dockerfile | |
tags: | | |
ghcr.io/oasisprotocol/${{ matrix.docker_image }}:local | |
load: true | |
- name: Test | |
timeout-minutes: 3 | |
working-directory: docker/${{ matrix.docker_image }} | |
run: ./test.sh | |
- name: Export | |
run: docker save ghcr.io/oasisprotocol/${{ matrix.docker_image }}:local --output /tmp/${{ matrix.docker_image }}.tar | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.docker_image }} | |
path: /tmp/${{ matrix.docker_image }}.tar | |
- name: Push | |
if: ${{ github.event_name == 'push' && matrix.os == 'ubuntu-latest' }} | |
uses: docker/build-push-action@v6 | |
with: | |
build-args: | | |
VERSION=${{ env.VERSION }} | |
context: . | |
file: docker/${{ matrix.docker_image }}/Dockerfile | |
tags: | | |
ghcr.io/oasisprotocol/${{ matrix.docker_image }}:latest | |
ghcr.io/oasisprotocol/${{ matrix.docker_image }}:latest-${{ env.VERSION }} | |
push: true | |
labels: | | |
org.opencontainers.image.source=${{ github.event.repository.html_url }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
- name: Prune old ghcr.io/oasisprotocol/${{ matrix.docker_image }} images | |
if: ${{ github.event_name == 'push' && matrix.os == 'ubuntu-latest' }} | |
uses: vlaurin/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
organization: oasisprotocol | |
container: ${{ matrix.docker_image }} | |
keep-younger-than: 7 # days | |
keep-last: 2 | |
prune-untagged: true | |
prune-tags-regexes: ^latest- | |
mac: | |
needs: docker | |
strategy: | |
matrix: | |
docker_image: [sapphire-localnet] | |
runs-on: macos-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
# We need history to determine oasis-web3-gateway version from git tag. | |
fetch-depth: 0 | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ matrix.docker_image }} | |
path: /tmp | |
- name: Setup Docker | |
run: | | |
brew install docker colima docker-buildx | |
- name: Start Colima | |
run: colima start --network-address --arch arm64 --vm-type=qemu | |
- name: Load image | |
run: | | |
docker load --input /tmp/${{ matrix.docker_image }}.tar | |
docker image ls -a | |
- name: Test | |
timeout-minutes: 3 | |
working-directory: docker/sapphire-localnet | |
run: ./test.sh |