Skip to content

Commit 0a85ca6

Browse files
authored
Merge pull request #406 from alliander-opensource/341-test-architecture
341-test-architecture
2 parents b06f3d8 + 40572d1 commit 0a85ca6

22 files changed

Lines changed: 1470 additions & 1008 deletions
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# SPDX-FileCopyrightText: Alliander N. V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: deploy-image
6+
description: Build and push a Docker image to Docker Hub.
7+
inputs:
8+
component:
9+
description: "Component to deploy."
10+
required: true
11+
tag:
12+
description: "Tag to use for the image."
13+
required: false
14+
default: "latest"
15+
runner:
16+
description: "Runner to use for deployment."
17+
required: true
18+
DOCKER_USERNAME:
19+
description: "Docker Hub username."
20+
required: true
21+
DOCKER_TOKEN:
22+
description: "Docker Hub token."
23+
required: true
24+
free-disk-space-before:
25+
description: "Free disk space before deployment."
26+
required: false
27+
default: "false"
28+
29+
runs:
30+
using: "composite"
31+
steps:
32+
- name: Free disk space
33+
if: ${{ inputs.free-disk-space-before == 'true' }}
34+
uses: ./.github/actions/free-disk-space
35+
- name: Set architecture
36+
shell: bash
37+
id: arch
38+
run: |
39+
if [[ "${{ inputs.runner }}" == *"-arm"* ]]; then
40+
echo "arch=arm64" >> $GITHUB_OUTPUT
41+
else
42+
echo "arch=amd64" >> $GITHUB_OUTPUT
43+
fi
44+
- name: Get variables for ${{ inputs.component }}
45+
shell: bash
46+
id: variables
47+
run: |
48+
echo "BASE_IMAGE=$(yq .${{ inputs.component }}.base_image components.yml)" >> $GITHUB_OUTPUT
49+
echo "REPOSITORY=$(yq .${{ inputs.component }}.repository components.yml)" >> $GITHUB_OUTPUT
50+
echo "DOCKERFILE=$(yq .${{ inputs.component }}.dockerfile components.yml)" >> $GITHUB_OUTPUT
51+
- name: Setup Docker Buildx
52+
uses: docker/setup-buildx-action@v4
53+
- name: Docker login
54+
uses: docker/login-action@v4
55+
with:
56+
username: ${{ inputs.DOCKER_USERNAME }}
57+
password: ${{ inputs.DOCKER_TOKEN }}
58+
- name: Build and push ${{ inputs.component }}-${{ steps.arch.outputs.arch }}
59+
uses: docker/build-push-action@v7
60+
with:
61+
push: true
62+
context: .
63+
file: ${{ steps.variables.outputs.DOCKERFILE }}
64+
tags: ${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }}-${{ steps.arch.outputs.arch }}
65+
build-args: BASE_IMAGE=${{ steps.variables.outputs.BASE_IMAGE }}:latest-${{ steps.arch.outputs.arch }}
66+
cache-from: |
67+
type=registry,ref=${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }}-${{ steps.arch.outputs.arch }}-cache
68+
type=registry,ref=${{ steps.variables.outputs.BASE_IMAGE}}:${{ inputs.tag }}-${{ steps.arch.outputs.arch }}-cache
69+
type=registry,ref=${{ steps.variables.outputs.REPOSITORY }}:latest-${{ steps.arch.outputs.arch }}-cache
70+
type=registry,ref=${{ steps.variables.outputs.BASE_IMAGE}}:latest-${{ steps.arch.outputs.arch }}-cache
71+
cache-to: |
72+
type=registry,ref=${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }}-${{ steps.arch.outputs.arch }}-cache,mode=max
73+
- name: Create manifest for ${{ inputs.component }}
74+
shell: bash
75+
run: |
76+
# TODO remove this when all components have both amd64 and arm64 images
77+
if docker manifest inspect ${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }}-arm64 > /dev/null 2>&1; then
78+
docker buildx imagetools create -t \
79+
${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }} \
80+
${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }}-amd64 \
81+
${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }}-arm64
82+
else
83+
docker buildx imagetools create -t \
84+
${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }} \
85+
${{ steps.variables.outputs.REPOSITORY }}:${{ inputs.tag }}-amd64
86+
fi

0 commit comments

Comments
 (0)