From 04504120283622b8a0cd2f32e5ec0961a58f300c Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Fri, 13 Dec 2024 10:38:53 +1300 Subject: [PATCH] build: create containers from pull requests for testing (#3380) ### Motivation The master branch should be have tested code run on it, sometime we need containers to be built and pushed so that we can use the containers in other locations eg github actions or argo workflows ### Modifications adds a "container" label that can be added to pull requests to generate containers for the server and CLI ### Verification --------- Co-authored-by: Wentao Kuang --- .github/workflows/containers.yml | 9 ++- .github/workflows/pull-request-container.yml | 67 ++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pull-request-container.yml diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index 3e694aa3b..2292fe00e 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -53,8 +53,13 @@ jobs: cp -r packages/lambda-tiler/static/ packages/server/ cp -r packages/lambda-tiler/static/ packages/cli/ - - name: Log in to registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + + - name: Login to GitHub Container Registry + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - name: '@basemaps/cli - Build and export to Docker' uses: docker/build-push-action@v5 diff --git a/.github/workflows/pull-request-container.yml b/.github/workflows/pull-request-container.yml new file mode 100644 index 000000000..03c3e36ff --- /dev/null +++ b/.github/workflows/pull-request-container.yml @@ -0,0 +1,67 @@ +name: Pull Request Containers + +on: + pull_request: + branches: + - master + types: [labeled, synchronize, opened] + +jobs: + containers: + name: Create containers + runs-on: ubuntu-latest + + if: | + contains(github.event.pull_request.labels.*.name, 'container') + + permissions: + id-token: write + contents: read + packages: write + + steps: + - uses: linz/action-typescript@v3 + + - name: Bundle & Package all files + run: | + npx lerna run bundle --stream + npm pack --workspaces + + - name: Set up Docker Qemu + id: qemu + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Copy packages and files + run: | + # Files are packed into the base directory + cp *.tgz packages/server/ + cp *.tgz packages/cli/ + cp -r packages/lambda-tiler/static/ packages/server/ + cp -r packages/lambda-tiler/static/ packages/cli/ + + - name: Login to GitHub Container Registry + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: '@basemaps/cli - Build and push cli PR container' + uses: docker/build-push-action@v5 + with: + context: packages/cli + platforms: linux/arm64,linux/amd64 + tags: 'ghcr.io/${{ github.repository }}/cli:pr-${{ github.event.number }}' + push: true + + - name: '@basemaps/server - Build and push server PR container' + uses: docker/build-push-action@v5 + with: + context: packages/server + platforms: linux/arm64,linux/amd64 + tags: ghcr.io/${{ github.repository }}/server:pr-${{ github.event.number }} + push: true