Skip to content

Commit 2209924

Browse files
committed
Use GitHub Actions for Docker build
1 parent 02ed685 commit 2209924

12 files changed

+144
-229
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# see https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
2+
name: Create and publish Docker images
3+
4+
on:
5+
push
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
NAMESPACE: isaacphysics
10+
11+
jobs:
12+
build-and-push-image:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
attestations: write
18+
id-token: write
19+
20+
strategy:
21+
matrix:
22+
target: [build-phy, build-phy-renderer, build-ada, build-ada-renderer]
23+
include:
24+
- target: build-phy
25+
image-name: isaac-phy-app
26+
- target: build-phy-renderer
27+
image-name: isaac-phy-app-renderer
28+
- target: build-ada
29+
image-name: isaac-ada-app
30+
- target: build-ada-renderer
31+
image-name: isaac-ada-app-renderer
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
- name: Log in to the Container registry
37+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
- name: Get metadata for image
43+
id: meta
44+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image-name }}
47+
tags: |
48+
type=sha,prefix=,format=long
49+
type=ref,event=branch
50+
type=ref,event=tag
51+
type=ref,event=pr
52+
- name: Load API version from .env file for release
53+
if: startsWith(github.ref, 'refs/tags/v')
54+
run: |
55+
source .env
56+
echo REACT_APP_API_VERSION="$REACT_APP_API_VERSION" >> $GITHUB_ENV
57+
- name: Build and push image for release
58+
# If this is a release tag (vX.Y.Z), bake in the API version defined in .env.
59+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
60+
if: startsWith(github.ref, 'refs/tags/v')
61+
with:
62+
context: .
63+
build-args: |
64+
BUILD_TARGET=${{ matrix.target }}
65+
REACT_APP_API_VERSION=${{ env.REACT_APP_API_VERSION }}
66+
push: true
67+
tags: ${{ steps.meta.outputs.tags }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
- name: Build and push image
70+
# Otherwise, assume there is an API branch or tag with the same name(!) and override the app to use that.
71+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
72+
if: startsWith(github.ref, 'refs/tags/v') != true
73+
with:
74+
context: .
75+
build-args: |
76+
BUILD_TARGET=${{ matrix.target }}
77+
REACT_APP_API_VERSION=${{ steps.meta.outputs.version }}
78+
push: true
79+
tags: ${{ steps.meta.outputs.tags }}
80+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bundle-stats-*.json
1515

1616
# production
1717
/build
18-
/build-physics
18+
/build-phy
1919
/build-ada
2020
/build-phy-renderer
2121
/build-ada-renderer

Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
FROM nginx:stable
1+
ARG BUILD_TARGET="build-phy"
2+
3+
FROM node:20.12.0-buster AS builder
4+
ARG BUILD_TARGET
5+
ARG REACT_APP_API_VERSION
6+
7+
RUN mkdir /build
8+
WORKDIR /build
29

3-
ARG API_VERSION
4-
ARG SUBJECT
5-
ARG RENDERER_PATH=""
10+
COPY package.json /build
11+
COPY yarn.lock /build
12+
RUN yarn install --frozen-lockfile
13+
14+
COPY . /build
15+
RUN yarn $BUILD_TARGET
16+
17+
FROM nginx:stable
18+
ARG BUILD_TARGET
19+
ARG REACT_APP_API_VERSION
620

21+
COPY --from=builder /build/$BUILD_TARGET/ /usr/share/nginx/html
722
COPY nginx.conf /etc/nginx/nginx.conf
8-
COPY ./build-$SUBJECT$RENDERER_PATH/ /usr/share/nginx/html
923

10-
LABEL apiVersion=$API_VERSION
24+
LABEL apiVersion=$REACT_APP_API_VERSION

Dockerfile-Builder

Lines changed: 0 additions & 27 deletions
This file was deleted.

build-in-docker.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

build.sh

Lines changed: 0 additions & 129 deletions
This file was deleted.

compose

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ if [ $# -lt 4 ] || ! { [ $1 = "ada" ] || [ $1 = "phy" ]; } || ! { [ $2 = "dev" ]
1515
exit 1
1616
fi
1717

18+
DOCKER_REPO=ghcr.io/isaacphysics
19+
1820
# Extract args:
1921
SITE=$1
2022
ENV=$2
@@ -26,13 +28,13 @@ shift 3
2628
# Use the app image to find the correct API version to use:
2729
if [ $1 = "create" ] || [ $1 = "pull" ] || [ $1 = "push" ] || [ $1 = "run" ] || [ $1 = "start" ] || [ $1 = "up" ]; then
2830
# This will cause new containers or should update containers, so pull newer images if possible:
29-
docker pull docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION
30-
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION)
31-
docker pull docker.isaacscience.org/isaac-api:$API_VERSION
31+
docker pull $DOCKER_REPO/isaac-$SITE-app:$APP_VERSION
32+
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-$SITE-app:$APP_VERSION)
33+
docker pull $DOCKER_REPO/isaac-api:$API_VERSION
3234

3335
elif [ $1 = "down" ] || [ $1 = "stop" ] || [ $1 = "restart" ] || [ $1 = "exec" ] || [ $1 = "config" ] || [ $1 = "logs" ] || [ $1 = "kill" ] || [ $1 = "ps" ]; then
3436
# This affects existing containers, so don't pull newer images:
35-
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION)
37+
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-$SITE-app:$APP_VERSION)
3638

3739
else
3840
# This might not be a docker-compose operation. If it is, it could be added above to the correct branch.
@@ -63,15 +65,15 @@ version: '2'
6365
services:
6466
$APP_NAME:
6567
container_name: $APP_NAME
66-
image: docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION
68+
image: $DOCKER_REPO/isaac-$SITE-app:$APP_VERSION
6769
restart: "no"
6870
networks:
6971
default:
7072
aliases:
7173
- $SITE-app-$ENV
7274
$API_NAME:
7375
container_name: $API_NAME
74-
image: docker.isaacscience.org/isaac-api:$API_VERSION
76+
image: $DOCKER_REPO/isaac-api:$API_VERSION
7577
restart: "no"
7678
extra_hosts:
7779
- local-smtp:$LOCAL_SMTP

compose-builder.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

compose-etl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if [ $# -lt 3 ] || ! { [ $1 = "ada" ] || [ $1 = "phy" ]; }; then
1010
exit 1
1111
fi
1212

13+
DOCKER_REPO=ghcr.io/isaacphysics
14+
1315
# Extract args:
1416
SITE=$1
1517
APP_VERSION=$2
@@ -20,13 +22,13 @@ shift 2
2022
# Use the app image to find the correct API version to use:
2123
if [ $1 = "create" ] || [ $1 = "pull" ] || [ $1 = "push" ] || [ $1 = "run" ] || [ $1 = "start" ] || [ $1 = "up" ]; then
2224
# This will cause new containers or should update containers, so pull newer images if possible:
23-
docker pull docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION
24-
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION)
25-
docker pull docker.isaacscience.org/isaac-etl:$API_VERSION
25+
docker pull $DOCKER_REPO/isaac-$SITE-app:$APP_VERSION
26+
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-$SITE-app:$APP_VERSION)
27+
docker pull $DOCKER_REPO/isaac-etl:$API_VERSION
2628

2729
elif [ $1 = "down" ] || [ $1 = "stop" ] || [ $1 = "restart" ] || [ $1 = "exec" ] || [ $1 = "config" ] || [ $1 = "logs" ] || [ $1 = "kill" ] || [ $1 = "ps" ]; then
2830
# This affects existing containers, so don't pull newer images:
29-
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION)
31+
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-$SITE-app:$APP_VERSION)
3032

3133
else
3234
# This might not be a docker-compose operation. If it is, it could be added above to the correct branch.
@@ -55,7 +57,7 @@ version: '2'
5557
services:
5658
$SITE-etl:
5759
container_name: $ETL_NAME
58-
image: docker.isaacscience.org/isaac-etl:$API_VERSION
60+
image: $DOCKER_REPO/isaac-etl:$API_VERSION
5961
environment:
6062
- SEGUE_CONFIG_LOCATION=/local/data/config/segue-config.dec.yaml
6163
- JAVA_OPTIONS=-Dlog.path=/isaac-logs -Dsegue.version=$API_VERSION -Djetty.port=8090

0 commit comments

Comments
 (0)