[READ-ONLY] Mirror of https://github.com/FoxxMD/komodo-import. Import existing compose stacks into Komodo
foxxmd.github.io/komodo-import
compose
docker
import
komodo
toml
7.7 kB
222 lines
1name: PR Workflow
2
3concurrency:
4 group: ${{ github.workflow }}-${{ github.event.pull_request.head.sha }}
5 cancel-in-progress: true
6
7on:
8 pull_request_target:
9 types:
10 - labeled
11 - synchronize
12 - reopened
13 - opened
14 branches:
15 - 'main'
16
17jobs:
18 test:
19 if: contains(github.event.pull_request.labels.*.name, 'safe to test')
20 uses: ./.github/workflows/testAndSanity.yml
21 with:
22 ref: ${{ github.event.pull_request.head.sha }}
23
24 build-snapshot:
25 name: Build OCI snapshot
26 needs: test
27 if: contains(github.event.pull_request.labels.*.name, 'safe to test')
28 runs-on: ${{ matrix.os }}
29 permissions:
30 packages: write
31 contents: read
32 strategy:
33 fail-fast: false
34 matrix:
35 include:
36 - os: ubuntu-latest
37 arch: amd64
38 platform: linux/amd64
39 - os: ubuntu-24.04-arm
40 arch: arm64
41 platform: linux/arm64
42 steps:
43 - name: Prepare
44 run: |
45 platform=${{ matrix.platform }}
46 echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
47
48 # list all registries to push to and join all non-empty with comma
49 # https://unix.stackexchange.com/a/693165/116849
50 # https://stackoverflow.com/a/9429887/1469797
51 strings=("${{vars.DOCKERHUB_SLUG}}" "${{vars.GHCR_SLUG}}")
52 for i in ${!strings[@]}; do [[ -z ${strings[i]} ]] && unset strings[i]; done
53 joined_string=$(IFS=, ; echo "${strings[*]}")
54 echo "REGISTRIES_JOINED=$joined_string" >> $GITHUB_ENV
55
56 # do not use here!
57 # instead we can specify repo#sha in build-push-action so we only deal with foreign SHA for actually building image
58 # - uses: actions/checkout@v4
59 # with:
60 # ref: ${{ github.event.pull_request.head.sha }}
61
62 - name: Set short git commit SHA
63 run: |
64 short=$(echo "${{ github.event.pull_request.head.sha }}" | head -c7)
65 echo "COMMIT_SHORT_SHA=$short" >> $GITHUB_ENV
66
67 - name: Get App Version
68 id: appversion
69 env:
70 APP_VERSION: ${{ format('pr{0}-{1}', github.event.number, env.COMMIT_SHORT_SHA ) }}
71 run: |
72 echo appversion=$APP_VERSION >>${GITHUB_OUTPUT}
73
74 - name: Login to Docker Hub
75 if: ${{ vars.DOCKERHUB_SLUG != '' }}
76 uses: docker/login-action@v3
77 with:
78 username: ${{ secrets.DOCKER_USERNAME }}
79 password: ${{ secrets.DOCKER_PASSWORD }}
80
81 - name: Login to GitHub Container Registry
82 if: ${{ vars.GHCR_SLUG != '' }}
83 uses: docker/login-action@v3
84 with:
85 registry: ghcr.io
86 username: ${{ github.repository_owner }}
87 password: ${{ secrets.GITHUB_TOKEN }}
88
89 # metadata extract for docker labels/image names is done in merge job
90
91 - name: Set up Buildx
92 uses: docker/setup-buildx-action@v3
93
94 # https://github.com/docker/build-push-action/issues/671#issuecomment-1619353328
95 # for caching
96 - name: Build and push by digest
97 id: build
98 uses: docker/build-push-action@v6
99 with:
100 # specify foreign repo#sha from PR that is used to build image
101 context: ${{github.event.pull_request.head.repo.clone_url}}#${{github.event.pull_request.head.sha}}
102 build-args: |
103 APP_BUILD_VERSION=${{steps.appversion.outputs.appversion}}
104 platforms: ${{ matrix.platform }}
105 labels: ${{ steps.meta.outputs.labels }}
106 outputs: type=image,"name=${{ env.REGISTRIES_JOINED }}",push-by-digest=true,name-canonical=true,push=true
107 #cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
108 #cache-to: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
109
110 - name: Export digest
111 run: |
112 mkdir -p /tmp/digests
113 digest="${{ steps.build.outputs.digest }}"
114 touch "/tmp/digests/${digest#sha256:}"
115
116 - name: Upload digest
117 uses: actions/upload-artifact@v4
118 with:
119 name: digests-${{ env.PLATFORM_PAIR }}
120 path: /tmp/digests/*
121 if-no-files-found: error
122 retention-days: 1
123
124 release-snapshot:
125 name: Merge OCI Images and Push
126 if: ${{ vars.DOCKERHUB_SLUG != '' || vars.GHCR_SLUG != '' }}
127 runs-on: ubuntu-latest
128 permissions:
129 packages: write
130 contents: read
131 needs:
132 - build-snapshot
133 - test
134 steps:
135 - name: Download digests
136 uses: actions/download-artifact@v4
137 with:
138 path: /tmp/digests
139 pattern: digests-*
140 merge-multiple: true
141
142 - name: Login to Docker Hub
143 if: ${{ vars.DOCKERHUB_SLUG != '' }}
144 uses: docker/login-action@v3
145 with:
146 username: ${{ secrets.DOCKER_USERNAME }}
147 password: ${{ secrets.DOCKER_PASSWORD }}
148
149 - name: Login to GitHub Container Registry
150 if: ${{ vars.GHCR_SLUG != '' }}
151 uses: docker/login-action@v3
152 with:
153 registry: ghcr.io
154 username: ${{ github.repository_owner }}
155 password: ${{ secrets.GITHUB_TOKEN }}
156
157 - name: Set up Docker Buildx
158 uses: docker/setup-buildx-action@v3
159
160 - name: Extract metadata (tags, labels)
161 id: meta
162 uses: docker/metadata-action@v5
163 with:
164 images: |
165 ${{ vars.DOCKERHUB_SLUG }}
166 ${{ vars.GHCR_SLUG }}
167 # generate Docker tags based on the following events/attributes
168 # https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
169 tags: |
170 type=ref,event=pr
171 flavor: |
172 latest=false
173 labels: |
174 org.opencontainers.image.title=Komodo Import
175 org.opencontainers.image.description=Import existing resources into Komodo
176 org.opencontainers.image.vendor=FoxxMD
177
178 - name: Create manifest list and push dockerhub
179 if: ${{ vars.DOCKERHUB_SLUG != '' }}
180 working-directory: /tmp/digests
181 run: |
182 docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
183 $(printf '${{ vars.DOCKERHUB_SLUG }}@sha256:%s ' *)
184
185 - name: Create manifest list and push gchr
186 if: ${{ vars.GHCR_SLUG != '' }}
187 working-directory: /tmp/digests
188 run: |
189 docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
190 $(printf '${{ vars.GHCR_SLUG }}@sha256:%s ' *)
191
192 - name: Inspect image dockerhub
193 if: ${{ vars.DOCKERHUB_SLUG != '' }}
194 run: |
195 docker buildx imagetools inspect ${{ vars.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }}
196
197 - name: Inspect image ghcr
198 if: ${{ vars.GHCR_SLUG != '' }}
199 run: |
200 docker buildx imagetools inspect ${{ vars.GHCR_SLUG }}:${{ steps.meta.outputs.version }}
201
202
203 combine-and-comment:
204 name: Leave comment
205 runs-on: ubuntu-latest
206 needs: release-snapshot
207 if: contains(github.event.pull_request.labels.*.name, 'safe to test')
208 steps:
209 - name: Create comment
210 uses: marocchino/sticky-pull-request-comment@v2
211 with:
212 recreate: true
213 header: "pr-release"
214 message: |
215 #### :package: A new release has been made for this pull request.
216
217 To play around with this PR, pull an image:
218 * `foxxmd/komodo-import:pr-${{ github.event.number }}`
219
220 Images are available for x86_64 and ARM64.
221
222 > Latest commit: ${{ github.event.pull_request.head.sha }}