Skip to content

Commit b90c66b

Browse files
committed
WIP: reusable container workflow
1 parent 74816a4 commit b90c66b

File tree

6 files changed

+147
-134
lines changed

6 files changed

+147
-134
lines changed

.github/workflows/docker-release.yml

Lines changed: 30 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,37 @@ env:
2424
IS_PRERELEASE: ${{ github.event.release.prerelease || github.event.inputs.PRERELEASE }}
2525

2626
jobs:
27-
# ===============================================================
28-
# Building Dev Images
29-
# ===============================================================
27+
# This workaround is needed, as it's not possible to reference env.FOOBAR directly at this stage
28+
# - for ex. https://github.com/actions/runner/issues/1189
29+
release-container-prereq:
30+
runs-on: ubuntu-latest
31+
outputs:
32+
tag: ${{ steps.set-output-defaults.outputs.tag }}
33+
tag_latest: ${{ steps.set-output-defaults.outputs.tag_latest }}
34+
steps:
35+
- id: set-output-defaults
36+
run: |
37+
echo "::set-output name=tag::${{ env.IS_PRERELEASE == 'true' && 'alpha' || 'ubuntu' }}"
38+
echo "::set-output name=tag_latest::${{ env.IS_PRERELEASE == 'true' && 'false' || 'true' }}"
39+
40+
release-container:
41+
needs: release-container-prereq
42+
uses: ./.github/workflows/reusable-container-workflow.yaml
43+
with:
44+
dockerfile: tools/docker/Dockerfile.ubuntu-prod
45+
tag: ${{ needs.release-container-prereq.outputs.tag }}
46+
tag_latest: ${{ needs.release-container-prereq.outputs.tag_latest == 'true' }}
47+
image: ghcr.io/${{ github.repository }}
48+
registry: ghcr.io
49+
registry_username: ${{ github.repository_owner }}
50+
fetch_release: true
51+
release_version: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
52+
secrets:
53+
registry_password: ${{ secrets.GITHUB_TOKEN }}
54+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
3056
release:
57+
needs: [release-container-prereq, release-container]
3158
runs-on: ubuntu-latest
3259
steps:
3360
- name: print_env
@@ -41,76 +68,6 @@ jobs:
4168
- name: Install helm
4269
uses: azure/setup-helm@v3
4370

44-
- uses: dsaltares/fetch-gh-release-asset@master
45-
with:
46-
version: 'tags/${{ env.TAG_NAME }}'
47-
regex: true
48-
file: "dragonfly-.*\\.tar\\.gz"
49-
target: 'releases/'
50-
token: ${{ secrets.GITHUB_TOKEN }}
51-
52-
- name: Set up QEMU
53-
id: qemu
54-
uses: docker/setup-qemu-action@v1
55-
with:
56-
platforms: arm64,amd64
57-
58-
- name: Set up Docker Buildx
59-
uses: docker/setup-buildx-action@v1
60-
61-
- name: Login to GitHub Container Registry
62-
uses: docker/login-action@v2
63-
with:
64-
registry: ghcr.io
65-
username: ${{ github.actor }}
66-
password: ${{ secrets.GITHUB_TOKEN }}
67-
68-
- name: Extract artifacts
69-
run: |
70-
echo "Event prerelease ${{ github.event.release.prerelease }}"
71-
echo "Input prerelease ${{ github.event.inputs.PRERELEASE }}"
72-
ls -l
73-
ls -l releases
74-
for f in releases/*.tar.gz; do tar xvfz $f -C releases; done
75-
rm releases/*.tar.gz
76-
77-
- name: Build release image
78-
if: env.IS_PRERELEASE != 'true'
79-
uses: docker/build-push-action@v3
80-
with:
81-
context: .
82-
platforms: linux/amd64,linux/arm64
83-
84-
# Define QEMU settings inside the builder
85-
build-args: |
86-
QEMU_CPU=max,pauth-impdef=on
87-
88-
push: ${{ github.event_name != 'pull_request' }}
89-
tags: |
90-
ghcr.io/${{ github.repository }}:ubuntu
91-
ghcr.io/${{ github.repository }}:latest
92-
ghcr.io/${{ github.repository }}:${{ env.TAG_NAME }}
93-
ghcr.io/${{ github.repository }}:${{ env.TAG_NAME }}-ubuntu
94-
95-
file: tools/docker/Dockerfile.ubuntu-prod
96-
cache-from: type=registry,ref=${{ github.repository }}:latest
97-
cache-to: type=inline
98-
99-
- name: Build pre-release image
100-
if: env.IS_PRERELEASE == 'true'
101-
uses: docker/build-push-action@v3
102-
with:
103-
context: .
104-
platforms: linux/amd64,linux/arm64
105-
106-
push: ${{ github.event_name != 'pull_request' }}
107-
tags: |
108-
ghcr.io/${{ github.repository }}:alpha
109-
ghcr.io/${{ github.repository }}:${{ env.TAG_NAME }}
110-
file: tools/docker/Dockerfile.ubuntu-prod
111-
cache-from: type=registry,ref=${{ github.repository }}:latest
112-
cache-to: type=inline
113-
11471
- name: Configure Git
11572
if: env.IS_PRERELEASE != 'true'
11673
run: |
Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: weekly docker build
2+
23
on:
34
schedule:
4-
- cron: '0 0 * * 1' # Monday midnight
5+
# Monday midnight
6+
- cron: '0 0 * * 1'
57
workflow_dispatch:
68

79
permissions:
@@ -11,51 +13,12 @@ permissions:
1113

1214
jobs:
1315
weekly-container-build:
14-
runs-on: ubuntu-latest
15-
16-
steps:
17-
- name: checkout
18-
uses: actions/checkout@v3
19-
with:
20-
fetch-depth: 0
21-
submodules: true
22-
23-
- name: Set up QEMU
24-
id: qemu
25-
uses: docker/setup-qemu-action@v1
26-
with:
27-
platforms: arm64,amd64
28-
29-
- name: Set up Docker Buildx
30-
uses: docker/setup-buildx-action@v1
31-
- name: Login to GitHub Container Registry
32-
uses: docker/login-action@v2
33-
with:
34-
registry: ghcr.io
35-
username: ${{ github.repository_owner }}
36-
password: ${{ secrets.GITHUB_TOKEN }}
37-
38-
- name: Docker meta
39-
id: metadata
40-
uses: docker/metadata-action@v3
41-
with:
42-
images: |
43-
ghcr.io/${{ github.repository }}
44-
tags: |
45-
type=raw,value=alpha
46-
type=raw,value=alpha-{{date 'YYYYMMDD'}}
47-
type=raw,value=alpha-{{sha}}
48-
49-
- name: Build release image
50-
uses: docker/build-push-action@v3
51-
with:
52-
context: .
53-
platforms: linux/amd64,linux/arm64
54-
build-args: |
55-
QEMU_CPU=max,pauth-impdef=on
56-
push: true
57-
tags: ${{ steps.metadata.outputs.tags }}
58-
labels: ${{ steps.metadata.outputs.labels }}
59-
file: tools/docker/Dockerfile.ubuntu-build
60-
cache-from: type=gha
61-
cache-to: type=gha,mode=max
16+
uses: ./.github/workflows/reusable-container-workflow.yaml
17+
with:
18+
dockerfile: tools/docker/Dockerfile.ubuntu-build
19+
tag: alpha
20+
image: ghcr.io/${{ github.repository }}
21+
registry: ghcr.io
22+
registry_username: ${{ github.repository_owner }}
23+
secrets:
24+
registry_password: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Reusable Container Build Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
dockerfile:
7+
required: true
8+
type: string
9+
tag:
10+
required: true
11+
type: string
12+
tag_latest:
13+
required: false
14+
type: boolean
15+
image:
16+
required: true
17+
type: string
18+
registry:
19+
required: true
20+
type: string
21+
registry_username:
22+
required: true
23+
type: string
24+
fetch_release:
25+
required: false
26+
type: boolean
27+
release_version:
28+
required: false
29+
type: string
30+
31+
secrets:
32+
registry_password:
33+
required: true
34+
GH_TOKEN:
35+
required: false
36+
37+
jobs:
38+
container-build:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: checkout
42+
uses: actions/checkout@v3
43+
with:
44+
fetch-depth: 1
45+
submodules: true
46+
47+
- if: inputs.fetch_release
48+
name: Fetch release asset
49+
uses: dsaltares/[email protected]
50+
with:
51+
version: "tags/${{ inputs.release_version }}"
52+
regex: true
53+
file: "dragonfly-.*\\.tar\\.gz"
54+
target: 'releases/'
55+
token: ${{ secrets.GH_TOKEN }}
56+
57+
- if: inputs.fetch_release
58+
name: Extract artifacts
59+
run: |
60+
echo "Event prerelease ${{ github.event.release.prerelease }}"
61+
echo "Input prerelease ${{ github.event.inputs.PRERELEASE }}"
62+
ls -l
63+
ls -l releases
64+
for f in releases/*.tar.gz; do tar xvfz $f -C releases; done
65+
rm releases/*.tar.gz
66+
67+
- name: Set up QEMU
68+
id: qemu
69+
uses: docker/setup-qemu-action@v1
70+
with:
71+
platforms: arm64,amd64
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v1
75+
- name: Login to GitHub Container Registry
76+
uses: docker/login-action@v2
77+
with:
78+
registry: ${{ inputs.registry }}
79+
username: ${{ inputs.registry_username }}
80+
password: ${{ secrets.registry_password }}
81+
82+
- name: Docker meta
83+
id: metadata
84+
uses: docker/metadata-action@v3
85+
with:
86+
images: |
87+
${{ inputs.image }}
88+
tags: |
89+
type=raw,value=latest,enable=${{ inputs.tag_latest }}
90+
type=raw,value=${{ inputs.tag }}
91+
type=raw,value=${{ inputs.release_version }}
92+
93+
- name: Build release image
94+
uses: docker/build-push-action@v3
95+
with:
96+
context: .
97+
platforms: linux/amd64,linux/arm64
98+
build-args: |
99+
QEMU_CPU=max,pauth-impdef=on
100+
push: true
101+
tags: ${{ steps.metadata.outputs.tags }}
102+
labels: ${{ steps.metadata.outputs.labels }}
103+
file: ${{ inputs.dockerfile }}
104+
cache-from: type=gha
105+
cache-to: type=gha,mode=max

tools/docker/Dockerfile.alpine-prod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ WORKDIR build-opt
1212
RUN ninja dragonfly
1313

1414
FROM alpine:latest
15-
ARG ORG_NAME=dragonflydb
16-
LABEL org.opencontainers.image.title Dragonfly
17-
LABEL org.opencontainers.image.source https://github.com/${ORG_NAME}/dragonfly
1815

1916
RUN addgroup -S -g 1000 dfly && adduser -S -G dfly -u 999 dfly
2017
RUN apk --no-cache add libgcc libstdc++ libunwind boost1.77-fiber \

tools/docker/Dockerfile.ubuntu-build

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ WORKDIR /build
55

66
COPY . ./
77

8-
# install build dependencies
9-
# taken from https://github.com/dragonflydb/dragonfly/blob/main/.github/workflows/release.yml#L60-L65
108
RUN \
119
rm -f /etc/apt/apt.conf.d/docker-clean; \
1210
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
@@ -23,16 +21,13 @@ RUN \
2321
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 40 \
2422
--slave /usr/bin/g++ g++ /usr/bin/g++-9
2523

26-
# build
27-
# taken from https://github.com/dragonflydb/dragonfly/blob/main/tools/release.sh
2824
RUN make release
2925

3026
RUN build-opt/dragonfly --version
3127

3228
RUN curl -O https://raw.githubusercontent.com/ncopa/su-exec/212b75144bbc06722fbd7661f651390dc47a43d1/su-exec.c && \
3329
gcc -Wall -O2 su-exec.c -o su-exec
3430

35-
# Now prod image
3631
FROM ubuntu:20.04
3732

3833
RUN \

tools/docker/Dockerfile.ubuntu-prod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ FROM ubuntu:20.04
1919
# ARG in fact change the env vars during the build process
2020
# ENV persist the env vars for the built image as well.
2121
ARG QEMU_CPU
22-
ARG ORG_NAME=dragonflydb
2322
ARG DEBIAN_FRONTEND=noninteractive
2423

25-
LABEL org.opencontainers.image.title Dragonfly
26-
LABEL org.opencontainers.image.source https://github.com/${ORG_NAME}/dragonfly
27-
2824
RUN apt clean && apt update && apt -y install netcat-openbsd
2925

3026

0 commit comments

Comments
 (0)