Skip to content

Commit

Permalink
adopt same approach as for api
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuhtz committed Jul 13, 2024
1 parent f3bda25 commit 6fe0369
Showing 1 changed file with 27 additions and 60 deletions.
87 changes: 27 additions & 60 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,81 +18,48 @@ on:
- 'cli/**/requirements.txt'
- '**/cli.yml'

env:
COMPONENT: cli

jobs:
containers:
build-and-push:
name: Build and push images
runs-on: ubuntu-latest

strategy:
matrix:
component: [ cli ]
platform: [ linux/amd64, linux/arm64 ]


# Cancel in-progress jobs if matching component and platform when new PR arrives.
concurrency:
group: containers-${{ matrix.component }}-${{ matrix.platform }}
group: cli
cancel-in-progress: true

steps:
- name: Create a variable with platform '${{ matrix.platform }}' value
run: echo "PLATFORM=${{ matrix.platform }}" >> $GITHUB_ENV

- name: Swap / for - in '${{ matrix.platform }}' and create local_platform variable
id: local_platform
run: |
LOCAL_PLATFORM="${PLATFORM//\//-}"
echo "LOCAL_PLATFORM=${LOCAL_PLATFORM}" >> $GITHUB_ENV
echo "local_platform=${LOCAL_PLATFORM}" >> $GITHUB_STATE
- name: checkout repo
- name: Checkout repo
uses: actions/checkout@v4

- name: setup docker buildx
- name: Set up QEMU
# if: matrix.architecture != 'amd64'
uses: docker/setup-qemu-action@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# with:
# buildkitd-flags: --debug

- name: Login to GitHub Container Registry
- name: Login to Docker Hub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Cache Docker layers
id: cache-docker-layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }}
key: ${{ runner.os }}-buildx
restore-keys: |
${{ runner.os }}-buildx
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# - name: Build and push (ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test)
# uses: docker/build-push-action@v6
# with:
# context: ./${{ matrix.component }}
# load: true
# tags: ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test
# platforms: ${{ matrix.platform }}
# cache-from: type=local,src=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }}
# cache-to: type=local,mode=max,dest=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }}

# # FIXME: this needs to be more than a do we exit with code 0 test..
# # https://github.com/ckuhtz/hamframe/issues/2
# - name: Run tests in container (ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test)
# run: docker run --rm --platform ${{ matrix.platform }} ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test

- name: Build and push (ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:latest)
# if: success()
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# logout: false

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.component }}
context: .
file: ./${{ env.COMPONENT }}/Dockerfile
push: true
tags: ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:latest
platforms: ${{ matrix.platform }}
cache-from: type=local,src=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }}
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }}

# cache-from: type=gha,scope=${{ matrix.architecture }}
# cache-to: type=gha,mode=max,scope=${{ matrix.architecture }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64, linux/arm64
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hamframe-${{ env.COMPONENT}}:latest

0 comments on commit 6fe0369

Please sign in to comment.