-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
132 lines (118 loc) · 4.95 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
name: Build Product Image
description: This action builds a product Docker image with a specific version
inputs:
product-name:
description: The name of the product to build via bake (directory name)
required: true
product-version:
description: The version of the product to build via bake
required: true
image-tools-version:
description: The Stackable image-tools version
default: 0.0.13
build-cache-username:
description: Build cache username
default: github
build-cache-password:
description: Build cache password
required: true
bake-config-file:
description: Path to the bake config file, defaults to `./conf.py`
default: ./conf.py
sdp-version:
description: |
Stackable Data Platform version (eg: `24.7.0`)
default: 0.0.0-dev
extra-tag-data:
description: |
Extra data to include in the final image manifest tag (eg: `pr321`)
outputs:
image-manifest-tag:
description: |
Human-readable tag (usually the version) with architecture information,
for example: `3.4.1-stackable0.0.0-dev-amd64`
value: ${{ steps.image_info.outputs.IMAGE_MANIFEST_TAG }}
suggested-image-index-manifest-tag:
description: |
Human-readable tag (usually the version) without architecture information,
for example: `3.4.1-stackable0.0.0-dev`
value: ${{ steps.image_info.outputs.IMAGE_INDEX_MANIFEST_TAG }}
runs:
using: composite
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
# NOTE (@Techassi): Why do we install python via apt and not the setup-python action?
- name: Setup Python
shell: bash
run: |
set -euo pipefail
sudo apt update
sudo apt install -y python3
- name: Install image-tools-stackabletech
shell: bash
run: pip install image-tools-stackabletech==${{ inputs.image-tools-version }}
# Needed if you pass the --cache argument to the bake command below
- name: Login to the docker build cache registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: build-repo.stackable.tech:8083
username: ${{ inputs.build-cache-username }}
password: ${{ inputs.build-cache-password }}
- name: Building ${{ inputs.product-name }} Container Image using bake
env:
BAKE_PRODUCT_VERSION: ${{ inputs.product-version }}
BAKE_CONFIG_FILE: ${{ inputs.bake-config-file }}
IMAGE_REPOSITORY: ${{ inputs.product-name }}
EXTRA_TAG_DATA: ${{ inputs.extra-tag-data }}
SDP_VERSION: ${{ inputs.sdp-version }}
shell: bash
run: |
set -euo pipefail
IMAGE_ARCH=$("$GITHUB_ACTION_PATH/../.scripts/get_architecture.sh")
# Will be either:
# - 3.9.2-stackable0.0.0-dev-arm64 or
# - 3.9.2-stackable0.0.0-dev-pr321-arm64
IMAGE_INDEX_MANIFEST_TAG="${SDP_VERSION}${EXTRA_TAG_DATA:+-$EXTRA_TAG_DATA}-${IMAGE_ARCH}"
echo "IMAGE_INDEX_MANIFEST_TAG=$IMAGE_INDEX_MANIFEST_TAG" | tee -a "$GITHUB_ENV"
# Validate that final tag is valid according to
# https://github.com/distribution/reference/blob/8c942b0459dfdcc5b6685581dd0a5a470f615bff/regexp.go#L68
if ! echo "$IMAGE_INDEX_MANIFEST_TAG" | grep --perl-regexp --quiet '^[\w][\w.-]{1,127}$'; then
>&2 echo "Encountered invalid image manifest tag: $IMAGE_INDEX_MANIFEST_TAG"
exit 1
fi
echo "::group::bake"
bake \
--product "$IMAGE_REPOSITORY=$BAKE_PRODUCT_VERSION" \
--image-version "$IMAGE_INDEX_MANIFEST_TAG" \
--architecture "linux/${IMAGE_ARCH}" \
--export-tags-file bake-target-tags \
--configuration "$BAKE_CONFIG_FILE" \
--cache
echo "::endgroup::"
- name: Re-tag Image (Temporary)
shell: bash
run: |
set -euo pipefail
# Extract the image uri and replace 'docker.stackable.tech/stackable'
# with 'localhost' until bake does the right thing
OLD_IMAGE_URI="$(< bake-target-tags)"
# Replace the image uri in the bake file
sed -i -e 's/docker\.stackable\.tech\/stackable/localhost/' bake-target-tags
# Finally, re-tag image
docker tag "$OLD_IMAGE_URI" "$(< bake-target-tags)"
- name: Extract Environment Variables
id: image_info
shell: bash
run: |
set -euo pipefail
echo "bake-target-tags: "$(< bake-target-tags)
# Extract the image manifest tag from the bake-target-tags file
IMAGE_MANIFEST_TAG=$(cut -d : -f 2 < bake-target-tags)
[[ -n "$IMAGE_MANIFEST_TAG" ]]
[[ -n "$IMAGE_INDEX_MANIFEST_TAG" ]]
# Add the contents of the env variables to the GitHub output, so that it
# can be used as action outputs
echo "IMAGE_MANIFEST_TAG=$IMAGE_MANIFEST_TAG" | tee -a "$GITHUB_OUTPUT"
echo "IMAGE_INDEX_MANIFEST_TAG=$IMAGE_INDEX_MANIFEST_TAG" | tee -a "$GITHUB_OUTPUT"