Skip to content

Commit b9dddaa

Browse files
authored
ci: build RabbitMQ image (#522)
1 parent a3dde5c commit b9dddaa

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

.github/workflows/docker.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,23 @@ jobs:
4040
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
4141
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
4242
- name: Build and push
43-
# https://github.com/docker/build-push-action/releases/tag/v6.7.0
44-
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85
43+
# https://github.com/docker/build-push-action/releases/tag/v6.15.0
44+
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
4545
with:
4646
push: true
4747
tags: ${{ steps.tags.outputs.tags }}
4848
platforms: linux/amd64,linux/arm64
4949
cache-from: type=gha
5050
cache-to: type=gha,mode=max
51+
- name: Build and push RabbitMQ image
52+
# https://github.com/docker/build-push-action/releases/tag/v6.15.0
53+
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
54+
if: steps.tags.outputs.rabbitmq_tags != ''
55+
with:
56+
build-args:
57+
ENABLE_RABBITMQ=true
58+
push: true
59+
tags: ${{ steps.tags.outputs.rabbitmq_tags }}
60+
platforms: linux/amd64,linux/arm64
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG IMG=node:22.11-alpine3.19
22

3-
FROM $IMG as builder
3+
FROM $IMG AS builder
44

55
WORKDIR /usr/src/app/
66

@@ -17,7 +17,7 @@ COPY config.js.docker ./src/config.js
1717

1818
RUN npm run build && npm run build-scripts
1919

20-
FROM $IMG as deps
20+
FROM $IMG AS deps
2121

2222
WORKDIR /usr/src/app/
2323
ENV NODE_ENV=production
@@ -27,8 +27,14 @@ ENV NODE_ENV=production
2727

2828
COPY package.json package-lock.json ./
2929
RUN apk add --no-cache --virtual .gyp python3 make g++ &&\
30-
npm ci --only=production &&\
31-
apk del .gyp &&\
30+
npm ci --only=production
31+
32+
# Install amqp library if RabbitMQ is enabled
33+
ARG ENABLE_RABBITMQ=false
34+
ENV ENABLE_RABBITMQ=${ENABLE_RABBITMQ}
35+
RUN if [ "$ENABLE_RABBITMQ" = "true" ]; then npm install amqplib@0.10.5; fi
36+
37+
RUN apk del .gyp &&\
3238
npm cache clean --force &&\
3339
rm -rf /tmp/* /var/cache/apk/*
3440

scripts/github/docker.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def prep_tags(environ: Dict):
1919
ref = environ.get('GITHUB_REF')
2020
sha = environ.get('GITHUB_SHA')
2121
tags = set()
22+
# These are used to deploy images with the RabbitMQ plugin included
23+
rabbitmq_tags = set()
2224

2325
if ref.startswith('refs/tags/'):
2426
git_tag = ref[10:]
@@ -39,10 +41,14 @@ def prep_tags(environ: Dict):
3941
tags.add(base_ecr_tag + version)
4042
tags.add(base_ecr_tag + '{}-{}'.format(sha, timestamp))
4143
tags.add(base_ecr_tag + 'latest')
44+
rabbitmq_tags.add(base_ecr_tag + version + '-rabbitmq')
45+
rabbitmq_tags.add(base_ecr_tag + 'latest-rabbitmq')
4246

4347
tags.add(base_dockerhub_tag + version)
4448
tags.add(base_dockerhub_tag + '{}-{}'.format(sha, timestamp))
4549
tags.add(base_dockerhub_tag + 'latest')
50+
rabbitmq_tags.add(base_dockerhub_tag + version + '-rabbitmq')
51+
rabbitmq_tags.add(base_dockerhub_tag + 'latest-rabbitmq')
4652
elif ref == 'refs/heads/master':
4753
# A push to master creates a staging tag
4854
tags.add(base_ecr_tag + 'staging-{}-{}'.format(sha, timestamp))
@@ -53,14 +59,16 @@ def prep_tags(environ: Dict):
5359
# XXX: We currently do not run on other branches
5460
tags.add(base_ecr_tag + 'dev-{}-{}'.format(sha, timestamp))
5561

56-
return tags
62+
return tags, rabbitmq_tags
5763

5864
def print_output(output: Dict):
5965
outputs = ['{}={}\n'.format(k, v) for k, v in output.items()]
6066
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
6167
f.writelines(outputs)
6268

6369
if __name__ == '__main__':
64-
tags = prep_tags(os.environ)
70+
tags, rabbitmq_tags = prep_tags(os.environ)
6571
if tags:
6672
print_output({'tags': ','.join(tags)})
73+
if rabbitmq_tags:
74+
print_output({'rabbitmq_tags': ','.join(rabbitmq_tags)})

0 commit comments

Comments
 (0)