From 2fce3987d3572849cbb41f19c5f6ea2d96cd59a9 Mon Sep 17 00:00:00 2001 From: James-Mart Date: Thu, 15 Feb 2024 12:03:12 -0500 Subject: [PATCH] try more idiomatic way of building the archive for PR workflow runs --- .github/scripts/free-disk-space.sh | 17 ------- .github/workflows/builder-ubuntu.yml | 41 +++++++--------- .github/workflows/contributor.yml | 72 +++++++++++++++------------- .github/workflows/tool-config.yml | 59 ++++++++++++++--------- 4 files changed, 92 insertions(+), 97 deletions(-) delete mode 100755 .github/scripts/free-disk-space.sh diff --git a/.github/scripts/free-disk-space.sh b/.github/scripts/free-disk-space.sh deleted file mode 100755 index 280ab2b..0000000 --- a/.github/scripts/free-disk-space.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -echo "==============================================================================" -echo "Freeing up disk space on CI system" -echo "==============================================================================" - -echo "Listing 100 largest packages" -dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100 -df -h -echo "Removing large packages" -sudo apt-get remove -y '^dotnet-.*' -sudo apt-get remove -y '^llvm-.*' -sudo apt-get remove -y 'php.*' -sudo apt-get remove -y azure-cli google-cloud-* google-chrome-stable firefox powershell mono* microsoft-edge-stable temurin-* -sudo apt-get autoremove -y -sudo apt-get clean -df -h \ No newline at end of file diff --git a/.github/workflows/builder-ubuntu.yml b/.github/workflows/builder-ubuntu.yml index 0d715a7..36e33a4 100644 --- a/.github/workflows/builder-ubuntu.yml +++ b/.github/workflows/builder-ubuntu.yml @@ -22,11 +22,6 @@ 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 @@ -34,33 +29,24 @@ 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-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 }} @@ -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: . @@ -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: diff --git a/.github/workflows/contributor.yml b/.github/workflows/contributor.yml index 1e18587..0348b78 100644 --- a/.github/workflows/contributor.yml +++ b/.github/workflows/contributor.yml @@ -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 @@ -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 @@ -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 }} @@ -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: diff --git a/.github/workflows/tool-config.yml b/.github/workflows/tool-config.yml index b986d67..ddb0a2d 100644 --- a/.github/workflows/tool-config.yml +++ b/.github/workflows/tool-config.yml @@ -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"] @@ -32,21 +27,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="${{ 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 @@ -54,16 +41,15 @@ jobs: 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 }} @@ -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: . @@ -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 \ No newline at end of file