Skip to content

Commit 3a61368

Browse files
authored
dev: publish images to ghcr on merge to main (#968)
* dev: push images to ghcr on main * dev: add same thing to on_pr as test * fix: require secrets * fix: swap order (duh) * fix: REALLY fix the credentials * fix: remove on_pr * fix: push to ecr on build completion instead * fix: pass variables * temp: run publish on pr for test * fix: actually login to ghcr * chore: remove on_pr publishing to ghcr bc of succesful test-n
1 parent 3b9d170 commit 3a61368

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

.github/workflows/ecrbuild-all.yml

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ on:
99
required: true
1010
AWS_SECRET_ACCESS_KEY:
1111
required: true
12+
inputs:
13+
publish_to_ghcr:
14+
type: boolean
15+
default: false
16+
outputs:
17+
core-image:
18+
description: "Core image SHA"
19+
value: ${{ jobs.build-core.outputs.image-sha}}
20+
base-image:
21+
description: "Base image SHA"
22+
value: ${{ jobs.build-base.outputs.image-sha }}
23+
jobs-image:
24+
description: "Jobs image SHA"
25+
value: ${{ jobs.build-jobs.outputs.image-sha }}
1226

1327
jobs:
1428
emit-sha-tag:
@@ -26,6 +40,9 @@ jobs:
2640
2741
build-base:
2842
uses: ./.github/workflows/ecrbuild-template.yml
43+
with:
44+
publish_to_ghcr: ${{ inputs.publish_to_ghcr }}
45+
ghcr_image_name: platform-migrations
2946
secrets:
3047
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3148
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -36,6 +53,8 @@ jobs:
3653
# - build-base
3754
with:
3855
package: core
56+
publish_to_ghcr: ${{ inputs.publish_to_ghcr }}
57+
ghcr_image_name: platform
3958
# we require a bigger lad
4059
# We are now public, default public runner is big enough
4160
# runner: ubuntu-latest-m
@@ -50,6 +69,8 @@ jobs:
5069
with:
5170
package: jobs
5271
target: jobs
72+
publish_to_ghcr: ${{ inputs.publish_to_ghcr }}
73+
ghcr_image_name: platform-jobs
5374
secrets:
5475
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
5576
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

.github/workflows/ecrbuild-template.yml

+34-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ on:
1212
default: ubuntu-latest
1313
target:
1414
type: string
15+
publish_to_ghcr:
16+
type: boolean
17+
default: false
18+
ghcr_image_name:
19+
type: string
20+
required: false
21+
outputs:
22+
image-sha:
23+
description: "Image SHA"
24+
value: ${{ jobs.build.outputs.image-sha }}
1525
secrets:
1626
AWS_ACCESS_KEY_ID:
1727
required: true
@@ -28,6 +38,8 @@ jobs:
2838
build:
2939
name: Build
3040
runs-on: ${{ inputs.runner }}
41+
outputs:
42+
image-sha: ${{ steps.label.outputs.label }}
3143

3244
steps:
3345
- name: Checkout
@@ -45,6 +57,13 @@ jobs:
4557
id: login-ecr
4658
uses: aws-actions/amazon-ecr-login@v2
4759

60+
- name: Login to GitHub Container Registry
61+
uses: docker/login-action@v3
62+
with:
63+
registry: ghcr.io
64+
username: ${{ github.actor }}
65+
password: ${{ secrets.GITHUB_TOKEN }}
66+
4867
# necessary in order to upload build source maps to sentry
4968
- name: Get sentry token
5069
id: sentry-token
@@ -75,6 +94,16 @@ jobs:
7594
echo "target=${TARGET:-next-app-${PACKAGE}}" >> $GITHUB_OUTPUT
7695
fi
7796
echo "label=$ECR_REGISTRY/$ECR_REPOSITORY_PREFIX$package_suffix:$sha_short" >> $GITHUB_OUTPUT
97+
if [[ ${{ inputs.publish_to_ghcr }} == "true" && -n ${{ inputs.ghcr_image_name }} ]]
98+
then
99+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
100+
101+
echo "ghcr_latest_label=ghcr.io/pubpub/${{ inputs.ghcr_image_name }}:latest" >> $GITHUB_OUTPUT
102+
103+
echo "ghcr_sha_label=ghcr.io/pubpub/${{ inputs.ghcr_image_name }}:$sha_short" >> $GITHUB_OUTPUT
104+
105+
echo "ghcr_timestamp_label=ghcr.io/pubpub/${{ inputs.ghcr_image_name }}:$TIMESTAMP" >> $GITHUB_OUTPUT
106+
fi
78107
79108
- name: Check if SENTRY_AUTH_TOKEN is set
80109
run: |
@@ -103,6 +132,10 @@ jobs:
103132
secrets: |
104133
SENTRY_AUTH_TOKEN=${{ env.SENTRY_AUTH_TOKEN }}
105134
target: ${{ steps.label.outputs.target }}
106-
tags: ${{ steps.label.outputs.label }}
135+
tags: |
136+
${{ steps.label.outputs.label }}
137+
${{ steps.label.outputs.ghcr_latest_label }}
138+
${{ steps.label.outputs.ghcr_sha_label }}
139+
${{ steps.label.outputs.ghcr_timestamp_label }}
107140
platforms: linux/amd64
108141
push: true

.github/workflows/on_main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
build-all:
1515
needs: ci
1616
uses: ./.github/workflows/ecrbuild-all.yml
17+
with:
18+
publish_to_ghcr: true
1719
secrets:
1820
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
1921
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

.github/workflows/on_pr.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414
jobs:
1515
ci:
1616
uses: ./.github/workflows/ci.yml
17+
1718
build-all:
1819
uses: ./.github/workflows/ecrbuild-all.yml
1920
secrets:

0 commit comments

Comments
 (0)