Skip to content

Commit

Permalink
try more idiomatic way of building the archive for PR workflow runs
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Mart committed Feb 15, 2024
1 parent c02f8c2 commit 2fce398
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 97 deletions.
17 changes: 0 additions & 17 deletions .github/scripts/free-disk-space.sh

This file was deleted.

41 changes: 16 additions & 25 deletions .github/workflows/builder-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,31 @@ jobs:
ubuntu-builder:
name: psibase-builder-ubuntu-${{ inputs.ubuntu_version }}
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 0

- name: Free up runner space
run: bash ${GITHUB_WORKSPACE}/.github/scripts/free-disk-space.sh

- name: Preparation
id: prep
run: |
OWNER="${{ github.repository_owner }}"
IMAGE="psibase-builder-ubuntu-${{ inputs.ubuntu_version }}"
if [[ "${{ inputs.is_pr }}" == "true" ]]; then
REGISTRY="localhost:5000"
TAG="latest"
else
REGISTRY="ghcr.io"
TAG="${{ github.sha }}"
fi
REGISTRY="ghcr.io"
TAG="${{ github.sha }}"
TAGS="${REGISTRY}/${OWNER}/${IMAGE}:${TAG}"
echo "tags=${TAGS,,}" >> $GITHUB_OUTPUT
- name: Building ${{ steps.prep.outputs.tags }}
run: true

- name: (PR only) - Config docker buildx network
if: ${{ inputs.is_pr }}
uses: docker/setup-buildx-action@v2
- name: Config docker buildx network
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
driver-opts: network=host

- name: Login in to registry
if: ${{ !inputs.is_pr }}
Expand All @@ -71,6 +57,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build & Publish Image
if: ${{ !inputs.is_pr }}
uses: docker/build-push-action@v4
with:
context: .
Expand All @@ -79,14 +66,18 @@ jobs:
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/amd64
outputs: type=image,annotation-index.org.opencontainers.image.description=Psibase build environment based on Ubuntu ${{ inputs.ubuntu_version }}

- name: (PR only) - Save docker image to archive
- name: (PR Only) - Build image archive
if: ${{ inputs.is_pr }}
run: |
docker pull ${{ steps.prep.outputs.tags }}
docker save ${{ steps.prep.outputs.tags }} -o builder-${{ inputs.ubuntu_version }}-image.tar
uses: docker/build-push-action@v4
with:
context: .
file: docker/ubuntu-${{ inputs.ubuntu_version }}-builder.Dockerfile
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/amd64
outputs: type=docker,dest=builder-${{ inputs.ubuntu_version }}-image.tar

- name: (PR only) - Upload docker image archive
- name: (PR only) - Upload image archive as artifact
if: ${{ inputs.is_pr }}
uses: actions/upload-artifact@v4
with:
Expand Down
72 changes: 40 additions & 32 deletions .github/workflows/contributor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,13 @@ jobs:
submodules: false
fetch-depth: 0

- name: Free up runner space
run: bash ${GITHUB_WORKSPACE}/.github/scripts/free-disk-space.sh

- name: Preparation
id: prep
run: |
OWNER="${{ github.repository_owner }}"
IMAGE="psibase-contributor"
if [[ "${{ inputs.is_pr }}" == "true" ]]; then
REGISTRY="localhost:5000"
TAG="latest"
else
REGISTRY="ghcr.io"
TAG="${{ github.sha }}"
fi
REGISTRY="ghcr.io"
TAG="${{ github.sha }}"
TAGS="${REGISTRY}/${OWNER}/${IMAGE}:${TAG}"
echo "tags=${TAGS,,}" >> $GITHUB_OUTPUT
Expand All @@ -61,12 +53,13 @@ jobs:

- name: (PR only) - Config docker buildx network
if: ${{ inputs.is_pr }}
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
driver-opts: network=host

- name: Login in to registry
if: ${{ !inputs.is_pr }}
uses: docker/login-action@v2
with:
registry: ghcr.io
Expand All @@ -82,8 +75,20 @@ jobs:
if: ${{ inputs.is_local_base }}
run: |
docker load -i builder-2204-image.tar
docker push localhost:5000/gofractally/psibase-builder-ubuntu-2204:latest
rm builder-2204-image.tar
- name: Set BASE_IMAGE
id: base_img
run: |
if [[ "${{ inputs.is_local_base }}" == "true" ]]; then
IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1)
LOCAL_TAG=local_base_image:latest
docker tag ${IMAGE} ${LOCAL_TAG}
docker push localhost:5000/${LOCAL_TAG}
echo "BASE_IMAGE=localhost:5000/${LOCAL_TAG}" >> $GITHUB_OUTPUT
else
latest_tag=$(./.github/scripts/latest-tag.sh "gofractally/psibase-builder-ubuntu-2204")
echo "BASE_IMAGE=ghcr.io/gofractally/psibase-builder-ubuntu-2204:${latest_tag}" >> $GITHUB_OUTPUT
fi
- name: Download local tools image
if: ${{ inputs.is_local_tools }}
Expand All @@ -94,47 +99,50 @@ jobs:
if: ${{ inputs.is_local_tools }}
run: |
docker load -i https-tool-config-image.tar
docker push localhost:5000/gofractally/https-tool-config:latest
rm https-tool-config-image.tar
# Base image is hardcoded to Ubuntu version 22.04
- name: Set docker image paths
id: image_paths
- name: Set TOOL_CONFIG_IMAGE
id: tool_cfg_img
run: |
if [[ "${{ inputs.is_local_base }}" == "true" ]]; then
echo "BASE_IMAGE=localhost:5000/gofractally/psibase-builder-ubuntu-2204:latest" >> $GITHUB_OUTPUT
else
latest_tag=$(./.github/scripts/latest-tag.sh "gofractally/psibase-builder-ubuntu-2204")
echo "BASE_IMAGE=ghcr.io/gofractally/psibase-builder-ubuntu-2204:${latest_tag}" >> $GITHUB_OUTPUT
fi
if [[ "${{ inputs.is_local_tools }}" == "true" ]]; then
echo "TOOL_CONFIG_IMAGE=localhost:5000/gofractally/https-tool-config:latest" >> $GITHUB_OUTPUT
IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1)
LOCAL_TAG=local_tools_image:latest
docker tag ${IMAGE} ${LOCAL_TAG}
docker push localhost:5000/${LOCAL_TAG}
echo "TOOL_CONFIG_IMAGE=localhost:5000/${LOCAL_TAG}" >> $GITHUB_OUTPUT
else
latest_tag=$(./.github/scripts/latest-tag.sh "gofractally/https-tool-config")
echo "TOOL_CONFIG_IMAGE=ghcr.io/gofractally/https-tool-config:${latest_tag}" >> $GITHUB_OUTPUT
fi
- name: Build & Publish Image
if: ${{ !inputs.is_pr }}
uses: docker/build-push-action@v4
with:
context: .
push: true
build-args: |
BASE_IMAGE=${{ steps.image_paths.outputs.BASE_IMAGE }}
TOOL_CONFIG_IMAGE=${{ steps.image_paths.outputs.TOOL_CONFIG_IMAGE }}
BASE_IMAGE=${{ steps.base_img.outputs.BASE_IMAGE }}
TOOL_CONFIG_IMAGE=${{ steps.tool_cfg_img.outputs.TOOL_CONFIG_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

- name: (PR only) - Save docker image to archive
- name: (PR Only) - Build image archive
if: ${{ inputs.is_pr }}
run: |
docker pull ${{ steps.prep.outputs.tags }}
docker save ${{ steps.prep.outputs.tags }} -o pr-psibase_contributor.tar
uses: docker/build-push-action@v4
with:
context: .
pull: false
build-args: |
BASE_IMAGE=${{ steps.base_img.outputs.BASE_IMAGE }}
TOOL_CONFIG_IMAGE=${{ steps.tool_cfg_img.outputs.TOOL_CONFIG_IMAGE }}
file: docker/psibase-contributor.Dockerfile
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/amd64
outputs: type=docker,dest=psibase_contributor.tar

- name: (PR only) - Upload docker image archive as artifact
- name: (PR only) - Upload image archive as artifact
if: ${{ inputs.is_pr }}
uses: actions/upload-artifact@v4
with:
Expand Down
59 changes: 36 additions & 23 deletions .github/workflows/tool-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ jobs:
tool-config:
name: tool-config
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
strategy:
matrix:
protocol: ["http", "https"]
Expand All @@ -32,38 +27,29 @@ jobs:
submodules: false
fetch-depth: 0

- name: Free up runner space
run: bash ${GITHUB_WORKSPACE}/.github/scripts/free-disk-space.sh

- name: Preparation
id: prep
run: |
OWNER="${{ github.repository_owner }}"
IMAGE="${{ matrix.protocol }}-tool-config"
if [[ "${{ inputs.is_pr }}" == "true" ]]; then
REGISTRY="localhost:5000"
TAG="latest"
else
REGISTRY="ghcr.io"
TAG="${{ github.sha }}"
fi
REGISTRY="ghcr.io"
TAG="${{ github.sha }}"
TAGS="${REGISTRY}/${OWNER}/${IMAGE}:${TAG}"
echo "tags=${TAGS,,}" >> $GITHUB_OUTPUT
- name: Building ${{ steps.prep.outputs.tags }}
run: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: 'arm64'

- name: (PR only) - Config docker buildx network
if: ${{ inputs.is_pr }}
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
driver-opts: network=host

- name: Login in to registry
if: ${{ !inputs.is_pr }}
Expand All @@ -74,6 +60,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build & Publish Image
if: ${{ !inputs.is_pr }}
uses: docker/build-push-action@v4
with:
context: .
Expand All @@ -85,16 +72,42 @@ jobs:
platforms: linux/amd64,linux/arm64
outputs: type=image,annotation-index.org.opencontainers.image.description=Config files for admin-sys dashboard tools connecting to psinode over ${{ matrix.protocol }} on 8080

- name: (PR only) - Save docker image to archive
- name: (PR Only) - Build image archive
if: ${{ inputs.is_pr }}
run: |
docker pull ${{ steps.prep.outputs.tags }}
docker save ${{ steps.prep.outputs.tags }} -o ${{ matrix.protocol }}-tool-config-image.tar
uses: docker/build-push-action@v4
with:
context: .
file: docker/tool-config.Dockerfile
build-args: |
protocol=${{ matrix.protocol }}
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/amd64
outputs: type=docker,dest=${{ matrix.protocol }}-tool-config-image.tar

- name: (PR only) - Upload docker image archive
- name: (PR Only) - Build separate arm image archive
if: ${{ inputs.is_pr }}
uses: docker/build-push-action@v4
with:
context: .
file: docker/tool-config.Dockerfile
build-args: |
protocol=${{ matrix.protocol }}
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/arm64
outputs: type=docker,dest=${{ matrix.protocol }}-tool-config-arm-image.tar

- name: (PR only) - Upload image archive as artifact
if: ${{ inputs.is_pr }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.protocol }}-tool-config-image
path: ${{ matrix.protocol }}-tool-config-image.tar
retention-days: 1

- name: (PR only) - Upload arm image archive as artifact
if: ${{ inputs.is_pr }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.protocol }}-tool-config-arm-image
path: ${{ matrix.protocol }}-tool-config-arm-image.tar
retention-days: 1

0 comments on commit 2fce398

Please sign in to comment.