Skip to content

Commit

Permalink
add docker build step
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Jan 5, 2024
1 parent cf4c22a commit fc84ab7
Showing 1 changed file with 32 additions and 80 deletions.
112 changes: 32 additions & 80 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,54 @@ run-name: Docker build CI triggered from @${{ github.actor }} of ${{ github.head

on:
workflow_dispatch:
merge_group:
pull_request:
push:
tags:
- "*"
branches:
- master
- develop
- release/*

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
docker:
name: Docker build
runs-on: ubuntu-8
services:
# local registery
registry:
image: registry:2
ports:
- 5000:5000
runs-on: ubuntu-20.04
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
driver-opts: network=host
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v3
- name: Generate docker tags/labels from github build context
id: meta
uses: docker/metadata-action@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }}
restore-keys: ${{ runner.os }}-buildx-

- name: Build nitro-node docker
uses: docker/build-push-action@v5
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# We tag latest only release of the form <variant>-v<major>.<minor>.<patch>-fh2.1 so "rc/beta" version are not flagged as latest
# - 2 docker tags: `{geth|bsc|...}-latest` and `{git-tag}`
tags: |
type=ref,event=tag,priority=1000,prefix=nitro-
type=ref,enable=true,priority=600,prefix=nitro-,suffix=,event=branch
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
target: nitro-node
push: true
context: .
tags: localhost:5000/nitro-node:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build nitro-node-dev docker
uses: docker/build-push-action@v5
with:
target: nitro-node-dev
file: ./Dockerfile
push: true
context: .
tags: localhost:5000/nitro-node-dev:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Start background nitro-testnode
shell: bash
run: |
cd nitro-testnode
./test-node.bash --init --dev &
- name: Wait for rpc to come up
shell: bash
run: |
${{ github.workspace }}/.github/workflows/waitForNitro.sh
- name: Print WAVM module root
id: module-root
run: |
# Unfortunately, `docker cp` seems to always result in a "permission denied"
# We work around this by piping a tarball through stdout
docker run --rm --entrypoint tar localhost:5000/nitro-node-dev:latest -cf - target/machines/latest | tar xf -
module_root="$(cat "target/machines/latest/module-root.txt")"
echo "name=module-root=$module_root" >> $GITHUB_STATE
echo -e "\x1b[1;34mWAVM module root:\x1b[0m $module_root"
- name: Upload WAVM machine as artifact
uses: actions/upload-artifact@v3
with:
name: wavm-machine-${{ steps.module-root.outputs.module-root }}
path: target/machines/latest/*
if-no-files-found: error

- name: Move cache
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Clear cache on failure
if: failure()
run: |
keys=(${{ runner.os }}-buildx- ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }})
for key in "${keys[@]}"; do
curl -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/caches/$key"
done
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit fc84ab7

Please sign in to comment.