Skip to content

Only upload builder artifacts from workflow runs triggered after merge #43

Only upload builder artifacts from workflow runs triggered after merge

Only upload builder artifacts from workflow runs triggered after merge #43

Workflow file for this run

name: Generate ubuntu-2204 images
env:
GITHUB_OUTPUT: ""
on:
push:
branches:
- main
paths:
- "docker/ubuntu-2204-builder.Dockerfile"
- ".github/workflows/ubuntu-2204.yml"
pull_request:
types: [opened, synchronize, reopened]
paths:
- "docker/ubuntu-2204-builder.Dockerfile"
- ".github/workflows/ubuntu-2204.yml"
workflow_run:
workflows: ["Generate tool-config images"]
types: [completed]
branches:
- 'main'
jobs:
ubuntu-2204-builder:
name: psibase-builder-ubuntu-2204
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: false
fetch-depth: 0
- name: Preparation
id: prep
run: |
OWNER="${{ github.repository_owner }}"
IMAGE="psibase-builder-ubuntu-2204"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
REGISTRY="localhost:5000"
TAG="latest"
else
REGISTRY="ghcr.io"
TAG="${{ github.sha }}"
fi
TAGS="${REGISTRY}/${OWNER}/${IMAGE}:${TAG}"
echo "tags=${TAGS,,}" >> $GITHUB_OUTPUT
- name: Showtag
id: showtag
run: echo ${{ steps.prep.outputs.tags }}
- name: (PR only) - Docker buildx config
if: github.event_name == 'pull_request'
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
driver-opts: network=host
- name: Login in to registry
if: github.event_name == 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build & Publish Image
uses: docker/build-push-action@v4
with:
context: .
push: true
file: docker/ubuntu-2204-builder.Dockerfile
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/amd64
outputs: type=image,annotation-index.org.opencontainers.image.description=Psibase build environment based on Ubuntu 22.04 (amd64)
- name: (PR only) - Save docker image to archive
if: github.event_name == 'pull_request'
run: |
echo "Pulling ${{ steps.prep.outputs.tags }}"
docker pull ${{ steps.prep.outputs.tags }}
docker images
echo "Saving ${{ github.repository_owner }}/psibase-builder-ubuntu-2204:latest"
docker save "${{ github.repository_owner }}/psibase-builder-ubuntu-2204:latest" -o temp-pr-image.tar
echo "Saving ${{ steps.prep.outputs.tags }}"
docker save "${{ steps.prep.outputs.tags }}" -o temp-pr-image2.tar
- name: (PR only) - Upload docker image archive
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: base-image
path: temp-pr-image.tar
psibase-contributor:
name: psibase-contributor
runs-on: ubuntu-latest
needs: ubuntu-2204-builder
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: false
fetch-depth: 0
- name: Preparation
id: prep
run: |
REGISTRY="ghcr.io"
IMAGE="${REGISTRY}/${{ github.repository_owner }}/psibase-contributor"
TAGS="${IMAGE}:${{ github.sha }},${IMAGE}:latest"
echo "tags=${TAGS,,}" >> $GITHUB_OUTPUT
- name: Showtag
id: showtag
run: echo ${{ steps.prep.outputs.tags }}
- name: Docker Buildx setup
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
- name: Login in to registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: PR exclusive - Download docker image archive
if: github.event_name == 'pull_request'
uses: actions/download-artifact@v3
with:
name: base-image
- name: PR exclusive - Install docker image from archive
run: |
docker load -i temp-pr-image.tar
- name: Set PARENT_IMAGE env
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "PARENT_IMAGE=pr-ghcr.io/gofractally/psibase-builder-ubuntu-2204:latest" >> $GITHUB_ENV
else
echo "PARENT_IMAGE=ghcr.io/gofractally/psibase-builder-ubuntu-2204:${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Build & Publish Image
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
build-args: |
PARENT_IMAGE=${{ env.PARENT_IMAGE }}
file: docker/psibase-contributor.Dockerfile
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/amd64
outputs: type=image,annotation-index.org.opencontainers.image.description=Psibase development environment