|
1 |
| ---- |
2 |
| -name: Build Product Image |
3 |
| -description: This action builds a product Docker image with a specific version |
4 |
| -inputs: |
5 |
| - product-name: |
6 |
| - description: The name of the product to build via bake (directory name) |
7 |
| - required: true |
8 |
| - product-version: |
9 |
| - description: The version of the product to build via bake |
10 |
| - required: true |
11 |
| - image-tools-version: |
12 |
| - description: The Stackable image-tools version |
13 |
| - default: 0.0.13 |
14 |
| - build-cache-username: |
15 |
| - description: Build cache username |
16 |
| - default: github |
17 |
| - build-cache-password: |
18 |
| - description: Build cache password |
19 |
| - required: true |
20 |
| -outputs: |
21 |
| - image-manifest-tag: |
22 |
| - description: | |
23 |
| - Human-readable tag (usually the version) with architecture information, |
24 |
| - for example: `3.4.1-stackable0.0.0-dev-amd64` |
25 |
| - value: ${{ steps.image_info.outputs.IMAGE_MANIFEST_TAG }} |
26 |
| -runs: |
27 |
| - using: composite |
28 |
| - steps: |
29 |
| - - name: Free Disk Space (Ubuntu) |
30 |
| - uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 |
31 |
| - with: |
32 |
| - # This might remove tools that are actually needed, if set to "true" but |
33 |
| - # frees about 6 GB. |
34 |
| - tool-cache: false |
35 |
| - |
36 |
| - # All of these default to true, but feel free to set to "false" if |
37 |
| - # necessary for your workflow. |
38 |
| - android: true |
39 |
| - dotnet: true |
40 |
| - haskell: true |
41 |
| - large-packages: true |
42 |
| - docker-images: true |
43 |
| - swap-storage: true |
44 |
| - |
45 |
| - - name: Setup Docker Buildx |
46 |
| - uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 |
47 |
| - |
48 |
| - # NOTE (@Techassi): Why do we install python via apt and not the setup-python action? |
49 |
| - - name: Setup Python |
50 |
| - shell: bash |
51 |
| - run: | |
52 |
| - set -euo pipefail |
53 |
| - sudo apt update |
54 |
| - sudo apt install -y python3 |
55 |
| -
|
56 |
| - - name: Building ${{ inputs.product-name }} |
57 |
| - shell: bash |
58 |
| - run: echo ${{ inputs.product-name }} |
59 |
| - |
60 |
| - - name: Install image-tools-stackabletech |
61 |
| - shell: bash |
62 |
| - run: pip install image-tools-stackabletech==${{ inputs.image-tools-version }} |
63 |
| - |
64 |
| - # Needed if you pass the --cache argument to the bake command below |
65 |
| - - name: Login to the docker build cache registry |
66 |
| - uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
67 |
| - with: |
68 |
| - registry: build-repo.stackable.tech:8083 |
69 |
| - username: ${{ inputs.build-cache-username }} |
70 |
| - password: ${{ inputs.build-cache-password }} |
71 |
| - |
72 |
| - - name: Build image using bake |
73 |
| - env: |
74 |
| - IMAGE_REPOSITORY: ${{ inputs.product-name }} |
75 |
| - BAKE_PRODUCT_VERSION: ${{ inputs.product-version }} |
76 |
| - shell: bash |
77 |
| - run: | |
78 |
| - set -euo pipefail |
79 |
| - IMAGE_ARCH="$(uname -m | sed -e 's#x86_64#amd64#' | sed -e 's#aarch64#arm64#')" |
80 |
| -
|
81 |
| - bake \ |
82 |
| - --product $IMAGE_REPOSITORY=$BAKE_PRODUCT_VERSION \ |
83 |
| - --image-version "0.0.0-dev-${IMAGE_ARCH}" \ |
84 |
| - --architecture "linux/${IMAGE_ARCH}" \ |
85 |
| - --export-tags-file bake-target-tags \ |
86 |
| - --cache |
87 |
| -
|
88 |
| - - name: Re-tag Image (Temporary) |
89 |
| - shell: bash |
90 |
| - run: | |
91 |
| - set -euo pipefail |
92 |
| -
|
93 |
| - # Extract the image uri and replace 'docker.stackable.tech/stackable' |
94 |
| - # with 'localhost' until bake does the right thing |
95 |
| - OLD_IMAGE_URI="$(< bake-target-tags)" |
96 |
| -
|
97 |
| - # Replace the image uri in the bake file |
98 |
| - sed -i -e 's/docker\.stackable\.tech\/stackable/localhost/' bake-target-tags |
99 |
| -
|
100 |
| - # Finally, re-tag image |
101 |
| - docker tag "$OLD_IMAGE_URI" "$(< bake-target-tags)" |
102 |
| -
|
103 |
| - - name: Extract Environment Variables |
104 |
| - id: image_info |
105 |
| - shell: bash |
106 |
| - run: | |
107 |
| - set -euo pipefail |
108 |
| - echo "bake-target-tags: "$(< bake-target-tags) |
109 |
| -
|
110 |
| - # Extract the image manifest tag from the bake-target-tags file |
111 |
| - IMAGE_MANIFEST_TAG=$(cut -d : -f 2 < bake-target-tags) |
112 |
| - [[ -n "$IMAGE_MANIFEST_TAG" ]] |
113 |
| -
|
114 |
| - # Add the contents of the env variables to the GitHub output, so that it |
115 |
| - # can be used as action outputs |
116 |
| - echo "IMAGE_MANIFEST_TAG=$IMAGE_MANIFEST_TAG" >> $GITHUB_OUTPUT |
0 commit comments