Skip to content

Commit

Permalink
Split image building (#3369)
Browse files Browse the repository at this point in the history
Co-authored-by: David Gauldie <dgauldie@uncharted.software>
  • Loading branch information
YohannParis and dgauldie authored Apr 24, 2024
1 parent 93f4ad4 commit d71a577
Show file tree
Hide file tree
Showing 11 changed files with 645 additions and 191 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/image-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# Create a new tag for the image
name: image-tag.yml
on:
workflow_call:
inputs:
image-name:
required: true
description: 'The name of the image to be built'
type: string
outputs:
tagged-image-name:
description: 'The tagged name of the image to be built'
value: ${{ jobs.image-tag.outputs.name }}
jobs:
image-tag:
name: Define image tag
runs-on: ubuntu-22.04
outputs:
name: ${{ steps.define.outputs.name }}
steps:
- name: Define the final tag based on the branch or tag
id: define
run: |
if [[ '${{ github.ref_type }}' == 'branch' && '${{ github.ref_name }}' == 'main' ]]; then
TAG=latest
else
SEMVER=$( echo ${{ github.ref_name }} | sed -nre 's/^v[^0-9]*(([0-9]+\.)*[0-9]+(-[a-z]+)?).*/\1/p')
if [[ -n $SEMVER ]]; then
TAG=${SEMVER}
else
TAG=${{ github.ref_name }}
fi
fi
IMAGE=${{ inputs.image-name }}:${TAG,,}
echo "$IMAGE"
echo "name=$IMAGE" >> $GITHUB_OUTPUT
1 change: 1 addition & 0 deletions .github/workflows/integration-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

name: Add integration tasks to Integration project

# yamllint disable-line rule:truthy
on:
issues:
types:
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/lint-types.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
---
name: Lint Generated Types

# yamllint disable-line rule:truthy
on:
workflow_call:
push:
paths:
- 'packages/client/hmi-client/src/types/Types.ts'
- 'packages/server/**'
- 'packages/server/src/main/java/**'
branches: ['main']
pull_request:
paths:
- 'packages/client/hmi-client/src/types/Types.ts'
- 'packages/server/**'
- 'packages/server/src/main/java/**'
branches: ['main']
jobs:
lintTypes:
Expand All @@ -22,7 +25,8 @@ jobs:
contents: write

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Setup Java v17
uses: actions/setup-java@v4
Expand All @@ -32,8 +36,7 @@ jobs:
cache: gradle

- name: Check Generated Types
run: |
./gradlew generateTypeScript
run: ./gradlew generateTypeScript

- name: Commit all changed files
uses: stefanzweifel/git-auto-commit-action@4b8a201e31cadd9829df349894b28c54e6c19fe6
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/merge-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
# Merge AMD64 and ARM64 images into one manifest
name: merge-images.yml

on:
workflow_call:
inputs:
name:
required: true
description: 'The name of the image to be merged'
type: string

jobs:
merge-images:
runs-on: ubuntu-22.04
steps:
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest
run: |
docker manifest create ${{ inputs.name }} \
--amend ${{ inputs.name }}--amd64 \
--amend ${{ inputs.name }}--arm64
docker manifest annotate --arch amd64 --os linux ${{ inputs.name }} ${{ inputs.name }}--amd64
docker manifest annotate --arch arm64 --os linux ${{ inputs.name }} ${{ inputs.name }}--arm64
- name: Inspect and push the manifest
run: |
docker manifest inspect ${{ inputs.name }}
docker manifest push ${{ inputs.name }}
- name: Delete the AMD64 and ARM64 manifest
continue-on-error: true
run: |
docker manifest rm ${{ inputs.name }}--amd64
docker manifest rm ${{ inputs.name }}--arm64
101 changes: 101 additions & 0 deletions .github/workflows/publish-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
# Automatically build and publish the client to the container registry.
# This workflow is triggered on changes to the client directory.

name: Build and Publish hmi-client

# yamllint disable-line rule:truthy
on:
push:
paths:
- 'packages/client/**'
branches:
- 'main'
tags:
- '*'

jobs:
image-tag:
name: Get tagged image name
uses: ./.github/workflows/image-tag.yml
with:
image-name: ghcr.io/darpa-askem/hmi-client

amd64:
runs-on: ubuntu-22.04
needs: image-tag
permissions:
contents: read
packages: write
steps:
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node 20.10.0 LTS
uses: actions/setup-node@v4
with:
node-version: 20.10.0

- name: Checkout the repository
uses: actions/checkout@v4

- name: Build hmi-client using Makefile
run: make image-hmi-client

- name: Create image and push
uses: docker/build-push-action@v5
with:
context: packages/client/hmi-client/docker
platforms: linux/amd64
push: true
tags: ${{ needs.image-tag.outputs.tagged-image-name }}--amd64

arm64-emulation:
runs-on: ubuntu-22.04
needs: image-tag
permissions:
contents: read
packages: write
steps:
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Node 20.10.0 LTS
uses: actions/setup-node@v4
with:
node-version: 20.10.0

- name: Checkout the repository
uses: actions/checkout@v4

- name: Build hmi-client using Makefile
run: make image-hmi-client

- name: Create image and push
uses: docker/build-push-action@v5
with:
context: packages/client/hmi-client/docker
platforms: linux/arm64
push: true
tags: ${{ needs.image-tag.outputs.tagged-image-name }}--arm64

merge-images:
name: Merge AMD64 and ARM64 images under one manifest
needs:
- image-tag
- amd64
- arm64-emulation
uses: ./.github/workflows/merge-images.yml
with:
name: ${{ needs.image-tag.outputs.tagged-image-name }}
114 changes: 114 additions & 0 deletions .github/workflows/publish-funman-taskrunner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
# Automatically build and publish the funman-taskrunner to the container registry.
# This workflow is triggered on changes to the funman-taskrunner directory.

name: Build and Publish funman-taskrunner

# yamllint disable-line rule:truthy
on:
push:
paths:
- 'packages/taskrunner/**'
- 'packages/funman/**'
branches:
- 'main'
tags:
- '*'

jobs:
image-tag:
name: Get tagged image name
uses: ./.github/workflows/image-tag.yml
with:
image-name: ghcr.io/darpa-askem/funman-taskrunner

amd64:
runs-on: ubuntu-22.04
needs: image-tag
permissions:
contents: read
packages: write
steps:
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout the repository
uses: actions/checkout@v4

- name: Validate GradleW JAR
uses: gradle/actions/wrapper-validation@v3

- name: Setup Java v17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: gradle

- name: Build funman-taskrunner using Makefile
run: make image-funman-taskrunner

- name: Create image and push
uses: docker/build-push-action@v5
with:
context: .
file: ./packages/funman/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ needs.image-tag.outputs.tagged-image-name }}--amd64

arm64-emulation:
runs-on: ubuntu-22.04
needs: image-tag
permissions:
contents: read
packages: write
steps:
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Checkout the repository
uses: actions/checkout@v4

- name: Validate GradleW JAR
uses: gradle/actions/wrapper-validation@v3

- name: Setup Java v17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: gradle

- name: Build funman-taskrunner using Makefile
run: make image-funman-taskrunner

- name: Create image and push
uses: docker/build-push-action@v5
with:
context: .
file: ./packages/funman/Dockerfile
platforms: linux/arm64
push: true
tags: ${{ needs.image-tag.outputs.tagged-image-name }}--arm64

merge-images:
name: Merge AMD64 and ARM64 images under one manifest
needs:
- image-tag
- amd64
- arm64-emulation
uses: ./.github/workflows/merge-images.yml
with:
name: ${{ needs.image-tag.outputs.tagged-image-name }}
Loading

0 comments on commit d71a577

Please sign in to comment.