Skip to content

Commit 2ae558b

Browse files
committed
Rework ci to push to our public ecr
1 parent 212983e commit 2ae558b

1 file changed

Lines changed: 53 additions & 102 deletions

File tree

.github/workflows/build-push.yaml

Lines changed: 53 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,66 @@
1-
name: Build-Test-Push
1+
name: Build
22

33
on:
4-
schedule:
5-
- cron: "5 4 * * 3"
6-
pull_request:
7-
paths-ignore:
8-
- "README.md"
9-
- "LICENSE.md"
104
push:
11-
paths-ignore:
12-
- "README.md"
13-
- "LICENSE.md"
5+
tags: ['*']
146

157
jobs:
16-
gather-versions:
17-
runs-on: ubuntu-24.04
18-
outputs:
19-
versions: ${{ steps.ruby-versions.outputs.versions }}
20-
metadata: ${{ steps.ruby-versions.outputs.metadata }}
21-
steps:
22-
- uses: moritzheiber/ruby-versions-action@v1
23-
name: Fetch latest Ruby versions
24-
id: ruby-versions
258

26-
build-test-push:
27-
needs: ["gather-versions"]
28-
strategy:
29-
matrix:
30-
version: ${{ fromJSON(needs.gather-versions.outputs.versions) }}
31-
image: [slim, ubuntu-22.04, ubuntu-24.04]
32-
platform: [amd64, arm64]
33-
include: ${{ fromJSON(needs.gather-versions.outputs.metadata) }}
34-
runs-on: ${{ matrix.platform == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
35-
steps:
36-
- name: Set image_name
37-
id: context
38-
run: |
39-
if [[ "${{ matrix.image }}" == "slim" ]] ; then
40-
echo "image_name=ruby:${{ matrix.version }}-slim" >> ${GITHUB_OUTPUT}
41-
elif [[ "${{ matrix.image }}" == "ubuntu-22.04" ]] ; then
42-
echo "image_name=ubuntu:22.04" >> ${GITHUB_OUTPUT}
43-
elif [[ "${{ matrix.image }}" == "ubuntu-24.04" ]] ; then
44-
echo "image_name=ubuntu:24.04" >> ${GITHUB_OUTPUT}
45-
fi
9+
build:
4610

47-
if [[ "${{ startsWith(matrix.version, '3.2') }}" == "true" ]] ; then
48-
echo "flags=--enable-yjit" >> ${GITHUB_OUTPUT}
49-
fi
50-
- uses: actions/checkout@v4
51-
- name: Login to GHCR
52-
uses: docker/login-action@v3
53-
with:
54-
registry: ghcr.io
55-
username: ${{ github.actor }}
56-
password: ${{ secrets.GITHUB_TOKEN }}
57-
- uses: docker/setup-buildx-action@v3
58-
- uses: docker/build-push-action@v6
59-
name: Build
60-
id: build
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
6116
with:
62-
platforms: linux/${{ matrix.platform }}
63-
push: ${{ github.ref == 'refs/heads/main' }}
64-
cache-from: type=gha
65-
cache-to: type=gha,mode=max
66-
build-args: |
67-
RUBY_VERSION=${{ matrix.version }}
68-
RUBY_CHECKSUM=${{ matrix.checksum }}
69-
IMAGE_NAME=${{ steps.context.outputs.image_name }}
70-
ADDITIONAL_FLAGS=${{ steps.context.outputs.flags }}
71-
provenance: false
72-
outputs: |
73-
type=image,name=ghcr.io/moritzheiber/ruby-jemalloc,push-by-digest=true,push=${{ github.ref == 'refs/heads/main' }}
74-
- name: Export digest
75-
if: github.ref == 'refs/heads/main'
76-
run: |
77-
mkdir -p /tmp/digests/${{ matrix.version }}-${{ matrix.image }}-${{ matrix.platform }}
78-
digest="${{ steps.build.outputs.digest }}"
79-
touch "/tmp/digests/${{ matrix.version }}-${{ matrix.image }}-${{ matrix.platform }}/${digest#sha256:}"
80-
- name: Upload digest
81-
if: github.ref == 'refs/heads/main'
82-
uses: actions/upload-artifact@v4
17+
fetch-depth: 1
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Extract branch name
23+
shell: bash
24+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | sed 's#/#_#g')"
25+
id: extract_refs
26+
27+
- name: Debug branch name
28+
run: echo "${{ steps.extract_refs.outputs.branch }}"
29+
30+
- name: Cache Docker layers
31+
uses: actions/cache@v4
8332
with:
84-
name: digests-${{ matrix.version }}-${{ matrix.image }}-${{ matrix.platform }}
85-
path: /tmp/digests/${{ matrix.version }}-${{ matrix.image }}-${{ matrix.platform }}/*
86-
if-no-files-found: error
87-
retention-days: 1
33+
path: /tmp/.buildx-cache
34+
key: ${{ runner.os }}-buildx-${{ github.ref }}
35+
restore-keys: |
36+
${{ runner.os }}-buildx-
8837
89-
merge-manifests:
90-
needs: ["build-test-push", "gather-versions"]
91-
if: github.ref == 'refs/heads/main'
92-
runs-on: ubuntu-24.04
93-
strategy:
94-
matrix:
95-
version: ${{ fromJSON(needs.gather-versions.outputs.versions) }}
96-
image: [slim, ubuntu-22.04, ubuntu-24.04]
97-
steps:
98-
- name: Login to GHCR
99-
uses: docker/login-action@v3
38+
- name: Build Image
39+
uses: docker/build-push-action@v5
10040
with:
101-
registry: ghcr.io
102-
username: ${{ github.actor }}
103-
password: ${{ secrets.GITHUB_TOKEN }}
104-
- uses: docker/setup-buildx-action@v3
105-
- name: Download digests
106-
uses: actions/download-artifact@v4
41+
context: .
42+
tags: ${{ vars.ECS_REPOSITORY_NAME }}:${{ github.ref }}
43+
load: true
44+
cache-from: type=local,src=/tmp/.buildx-cache
45+
cache-to: type=local,dest=/tmp/.buildx-cache-new
46+
build_args: |
47+
RUBY_VERSION=${{ github.ref }}
48+
49+
- name: Push Image to Amazon ECR
50+
id: ecr_sha_ruby
51+
uses: jwalton/gh-ecr-push@v2
10752
with:
108-
path: /tmp/digests/${{ matrix.version }}-${{ matrix.image }}
109-
pattern: digests-${{ matrix.version }}-${{ matrix.image }}-*
110-
merge-multiple: true
111-
- name: Create and push manifest
112-
working-directory: /tmp/digests/${{ matrix.version }}-${{ matrix.image }}
53+
access-key-id: ${{ vars.GH_AWS_ACCESS_KEY_ID }}
54+
secret-access-key: ${{ secrets.GH_AWS_SECRET_ACCESS_KEY }}
55+
region: eu-west-1
56+
local-image: ${{ vars.ECS_REPOSITORY_NAME }}:${{ github.ref }}
57+
image: ${{ vars.ECS_REPOSITORY_NAME }}:${{ github.ref }}, ${{ vars.ECS_REPOSITORY_NAME }}:${{ steps.extract_refs.outputs.branch }}
58+
59+
-
60+
# Temp fix
61+
# https://github.com/docker/build-push-action/issues/252
62+
# https://github.com/moby/buildkit/issues/1896
63+
name: Move cache
11364
run: |
114-
docker buildx imagetools create -t ghcr.io/moritzheiber/ruby-jemalloc:${{ matrix.version }}-${{ matrix.image }} \
115-
$(printf 'ghcr.io/moritzheiber/ruby-jemalloc@sha256:%s ' *)
65+
rm -rf /tmp/.buildx-cache
66+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 commit comments

Comments
 (0)