Skip to content

Commit aeafa70

Browse files
committed
TMP: push artifact
1 parent b0bf784 commit aeafa70

File tree

3 files changed

+85
-35
lines changed

3 files changed

+85
-35
lines changed

.github/actions/build/action.yml

+25-32
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
name: 'Docker Build'
22
description: 'Builds docker image'
33
inputs:
4-
push:
5-
required: true
6-
description: "Build and push image to registry (cannot be used together with load)"
7-
default: "false"
8-
password:
9-
required: false
10-
description: "Password for the registry"
11-
username:
12-
required: false
13-
description: "Username for the registry"
144
node_env:
155
required: false
166
description: "Node environment"
@@ -46,28 +36,11 @@ runs:
4636
version: latest
4737
buildkitd-flags: --debug
4838

49-
# Login to a registry to push the image
50-
- name: Login to Container Registry
51-
# Only login if we are pushing the image
52-
if: ${{ inputs.push == 'true' }}
53-
uses: docker/login-action@v3
54-
with:
55-
registry: ghcr.io
56-
username: ${{ inputs.username }}
57-
password: ${{ inputs.password }}
58-
5939
- name: Docker Image
6040
id: image
6141
shell: bash
6242
run: |
63-
registry="ghcr.io"
64-
repository="${{ github.repository }}"
65-
image="$registry/$repository"
66-
67-
echo "registry=$registry" >> $GITHUB_OUTPUT
68-
echo "repository=$repository" >> $GITHUB_OUTPUT
69-
echo "image=$image" >> $GITHUB_OUTPUT
70-
43+
echo "image=${{ github.repository }}" >> $GITHUB_OUTPUT
7144
cat $GITHUB_OUTPUT
7245
7346
- name: Docker meta
@@ -100,15 +73,35 @@ runs:
10073
10174
cat $GITHUB_OUTPUT
10275
76+
- name: Tar file
77+
id: tar
78+
shell: bash
79+
run: |
80+
echo "path=/tmp/${{ steps.meta.outputs.version }}" >> $GITHUB_OUTPUT
81+
10382
- name: Build Image
10483
id: build
10584
uses: docker/bake-action@v4
10685
env:
10786
DOCKER_TAG: ${{ steps.tag.outputs.tag }}
10887
with:
10988
targets: app
110-
push: ${{ inputs.push }}
111-
load: ${{ inputs.push == 'false' }}
11289
set: |
113-
*.cache-from=type=registry,ref=${{ steps.tag.outputs.tag_cache }}
114-
*.cache-to=type=registry,ref=${{ steps.tag.outputs.tag_cache }},mode=max,compression-level=9,force-compression=true,ignore-error=true
90+
*.output=type=docker,dest=${{ steps.tar.outputs.path }}
91+
92+
- name: Get image digest
93+
id: digest
94+
shell: bash
95+
run: |
96+
echo '${{ steps.build.outputs.metadata }}' > metadata.json
97+
echo "digest=$(cat metadata.json | jq -r '.app."containerimage.digest"')" >> $GITHUB_OUTPUT
98+
cat $GITHUB_OUTPUT
99+
100+
- name: Upload artifact
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: ${{ steps.meta.outputs.version }}
104+
path: ${{ steps.tar.outputs.path }}
105+
retention-days: 1
106+
compression-level: 9
107+
overwrite: true

.github/actions/push/action.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Docker Push image to registry'
2+
description: 'Pushes build docker image to registry'
3+
inputs:
4+
tag:
5+
required: true
6+
description: "The full docker tag to push"
7+
password:
8+
required: false
9+
description: "Password for the registry"
10+
username:
11+
required: false
12+
description: "Username for the registry"
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Login to Container Registry
18+
uses: docker/login-action@v3
19+
with:
20+
registry: ghcr.io
21+
username: ${{ inputs.username }}
22+
password: ${{ inputs.password }}
23+
24+
- name: Push Image
25+
shell: bash
26+
run: |
27+
docker image push ${{ inputs.tag }}

.github/workflows/push.yml

+33-3
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,52 @@ on:
99
permissions:
1010
packages: write
1111

12+
# TODO:
13+
# 1. split out the push action to separate action
14+
# 2. add caching based on fork behaviour, use GHA cache or registry..
15+
1216
jobs:
1317
build:
1418
runs-on: ubuntu-latest
1519

20+
outputs:
21+
version: ${{ steps.build.outputs.version }}
22+
1623
steps:
1724
- uses: actions/checkout@v4
1825

1926
- id: context
2027
uses: ./.github/actions/context
2128

2229
- uses: ./.github/actions/build
30+
id: build
2331
with:
24-
push: true
25-
username: ${{ github.actor }}
26-
password: ${{ secrets.GITHUB_TOKEN }}
2732
node_env: production
2833
latest: ${{ steps.context.outputs.is_release_master }}
2934

35+
- uses: ./.github/actions/push
36+
if: steps.context.outputs.is_fork == 'false'
37+
with:
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
download:
42+
runs-on: ubuntu-latest
43+
needs: [build]
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- uses: actions/download-artifact@v4
49+
with:
50+
name: ${{ needs.build.outputs.version }}
51+
path: /tmp/
52+
53+
- name: Load image
54+
shell: bash
55+
run: |
56+
docker load < /tmp/${{ needs.build.outputs.version }}
57+
docker image ls
58+
59+
3060

0 commit comments

Comments
 (0)