Skip to content

Commit cfe2172

Browse files
authored
Add build and deploy GitHub actions for AWS environments (#47)
* Add per-deployment build configs * Add github actions to build-and-publish docker images * Add missing DEPLOYMENT_ENV build args * Remove old github action * Refactor main.yml * Try production publishing * Give write permissions to the workflow * Add missing day to the tag * Run checks * Make build and publish steps consistent
1 parent 2a1637e commit cfe2172

7 files changed

+147
-75
lines changed

.deployment-envs/.env.production

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
NEXT_PUBLIC_NEXUS_URL=https://openbluebrain.com/api/nexus/v1
2+
NEXT_PUBLIC_BLUE_NAAS_URL=https://openbluebrain.com/api/bluenaas
3+
NEXT_PUBLIC_CELL_SVC_BASE_URL=https://openbluebrain.com/api/circuit
4+
NEXT_PUBLIC_KG_INFERENCE_BASE_URL=https://openbluebrain.com/api/kg-inference
5+
NEXT_PUBLIC_THUMBNAIL_GENERATION_BASE_URL=https://openbluebrain.com/api/thumbnail-generation
6+
NEXT_PUBLIC_SYNTHESIS_URL=https://synthesis.sbo.kcp.bbp.epfl.ch/synthesis-with-resources # TODO: change to staging
7+
NEXT_PUBLIC_ME_MODEL_ANALYSIS_WS_URL=wss://yyuu69y9fk.execute-api.us-east-1.amazonaws.com/prod/ # TODO: check if correct
8+
NEXT_PUBLIC_VIRTUAL_LAB_API_URL=https://openbluebrain.com/api/virtual-lab-manager
9+
NEXT_PUBLIC_BBS_ML_BASE_URL=https://openbluebrain.com/api/literature

.deployment-envs/.env.staging

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
NEXT_PUBLIC_NEXUS_URL=https://staging.openbraininstitute.org/api/nexus/v1
2+
NEXT_PUBLIC_BLUE_NAAS_URL=https://staging.openbraininstitute.org/api/bluenaas
3+
NEXT_PUBLIC_CELL_SVC_BASE_URL=https://staging.openbraininstitute.org/api/circuit
4+
NEXT_PUBLIC_KG_INFERENCE_BASE_URL=https://staging.openbraininstitute.org/api/kg-inference
5+
NEXT_PUBLIC_THUMBNAIL_GENERATION_BASE_URL=https://staging.openbraininstitute.org/api/thumbnail-generation
6+
NEXT_PUBLIC_SYNTHESIS_URL=https://synthesis.sbo.kcp.bbp.epfl.ch/synthesis-with-resources # TODO: change to staging
7+
NEXT_PUBLIC_ME_MODEL_ANALYSIS_WS_URL=wss://yyuu69y9fk.execute-api.us-east-1.amazonaws.com/prod/ # TODO: check if correct
8+
NEXT_PUBLIC_VIRTUAL_LAB_API_URL=https://staging.openbraininstitute.org/api/virtual-lab-manager
9+
NEXT_PUBLIC_BBS_ML_BASE_URL=https://staging.openbraininstitute.org/api/literature

.github/workflows/deploy-aws-prod.yml

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish PRODUCTION image
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
tag-and-publish-image:
11+
runs-on: ubuntu-latest
12+
env:
13+
ENVIRONMENT: staging
14+
IMAGE_NAME: ${{ vars.PUBLICECR_URI }}
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 # Get full history to check existing tags
20+
21+
- name: Set up Git
22+
run: |
23+
git config --global user.name "github-actions[bot]"
24+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
25+
26+
- name: Determine new tag
27+
id: tag
28+
run: |
29+
YEAR=$(date +'%Y')
30+
MONTH=$(date +'%m')
31+
DAY=$(date +'%d')
32+
LATEST_TAG=$(git tag --sort=-v:refname | grep -E "^${YEAR}\.${MONTH}\.${DAY}\.[0-9]+$" | head -n 1 || echo "")
33+
34+
if [[ -z "$LATEST_TAG" ]]; then
35+
COUNTER=1
36+
else
37+
COUNTER=$(( ${LATEST_TAG##*.} + 1 ))
38+
fi
39+
40+
NEW_TAG="${YEAR}.${MONTH}.${DAY}.${COUNTER}"
41+
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV
42+
echo "New tag: $NEW_TAG"
43+
44+
- name: Create Git Tag
45+
run: |
46+
git tag $NEW_TAG
47+
git push origin $NEW_TAG
48+
49+
- name: Configure AWS credentials
50+
uses: aws-actions/configure-aws-credentials@v4
51+
with:
52+
aws-access-key-id: ${{ secrets.PUBLICECR_UPLOAD_ACCESS_KEY_ID }}
53+
aws-secret-access-key: ${{ secrets.PUBLICECR_UPLOAD_SECRET_ACCESS_KEY }}
54+
aws-region: ${{ vars.PUBLICECR_REGION }}
55+
56+
- name: Authenticate with AWS Public ECR
57+
uses: aws-actions/amazon-ecr-login@v2
58+
with:
59+
registry-type: public
60+
61+
- name: Build a Docker image
62+
run: |
63+
docker build --build-arg DEPLOYMENT_ENV=production -t ${{ vars.PUBLICECR_URI }}:${{ env.NEW_TAG }} .
64+
65+
- name: Publish To AWS ECR
66+
run: |
67+
docker push ${{ vars.PUBLICECR_URI }}:$${{ env.NEW_TAG }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish STAGING image
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
workflow_dispatch:
8+
9+
jobs:
10+
publish-image:
11+
runs-on: ubuntu-latest
12+
env:
13+
ENVIRONMENT: staging
14+
IMAGE_NAME: ${{ vars.PUBLICECR_URI }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Configure AWS credentials
20+
uses: aws-actions/configure-aws-credentials@v4
21+
with:
22+
aws-access-key-id: ${{ secrets.PUBLICECR_UPLOAD_ACCESS_KEY_ID }}
23+
aws-secret-access-key: ${{ secrets.PUBLICECR_UPLOAD_SECRET_ACCESS_KEY }}
24+
aws-region: ${{ vars.PUBLICECR_REGION }}
25+
26+
- name: Authenticate with AWS Public ECR
27+
uses: aws-actions/amazon-ecr-login@v2
28+
with:
29+
registry-type: public
30+
31+
- name: Build a Docker image
32+
run: |
33+
docker build --build-arg DEPLOYMENT_ENV=staging -t ${{ vars.PUBLICECR_URI }}:staging .
34+
35+
- name: Publish To AWS ECR
36+
run: |
37+
docker push ${{ vars.PUBLICECR_URI }}:staging

.github/workflows/main.yml .github/workflows/run-checks.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: OBP CI/CD - Linter, Prettier, Test, Build
1+
name: Lint, Format, Test, Build
22

33
on:
44
push:
55
branches:
6-
- '*'
7-
- '!main'
8-
- '!develop'
6+
- "*"
7+
- "!main"
8+
- "!develop"
99
workflow_dispatch:
1010

1111
jobs:
@@ -18,8 +18,8 @@ jobs:
1818
- name: Set-up Node
1919
uses: actions/setup-node@v4
2020
with:
21-
node-version: 20
22-
cache: 'npm'
21+
node-version: 23
22+
cache: "npm"
2323

2424
- name: Install Node.js packages
2525
run: npm ci
@@ -33,8 +33,8 @@ jobs:
3333
- name: Set-up Node
3434
uses: actions/setup-node@v4
3535
with:
36-
node-version: 20
37-
cache: 'npm'
36+
node-version: 23
37+
cache: "npm"
3838

3939
- name: Install Node.js packages
4040
run: npm ci
@@ -51,8 +51,8 @@ jobs:
5151
- name: Set-up Node
5252
uses: actions/setup-node@v4
5353
with:
54-
node-version: 20
55-
cache: 'npm'
54+
node-version: 23
55+
cache: "npm"
5656

5757
- name: Install Node.js packages
5858
run: npm ci
@@ -69,8 +69,8 @@ jobs:
6969
- name: Set-up Node
7070
uses: actions/setup-node@v4
7171
with:
72-
node-version: 20
73-
cache: 'npm'
72+
node-version: 23
73+
cache: "npm"
7474

7575
- name: Install Node.js packages
7676
run: npm ci
@@ -89,8 +89,8 @@ jobs:
8989
- name: Set-up Node
9090
uses: actions/setup-node@v4
9191
with:
92-
node-version: 20
93-
cache: 'npm'
92+
node-version: 23
93+
cache: "npm"
9494

9595
- name: Install Node.js packages
9696
run: npm ci

Dockerfile

+11-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Install dependencies only when needed
2-
FROM node:21-alpine AS deps
2+
FROM node:23-alpine AS deps
33
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine
44
# to understand why libc6-compat might be needed.
55
RUN apk add --no-cache libc6-compat
@@ -11,39 +11,27 @@ RUN npm ci
1111

1212

1313
# Rebuild the source code only when needed
14-
FROM node:21-alpine AS builder
15-
16-
ARG NEXT_PUBLIC_SENTRY_DSN
17-
ARG SENTRY_AUTH_TOKEN
18-
ARG NEXT_PUBLIC_BASE_PATH
19-
ARG NEXT_PUBLIC_NEXUS_URL
20-
ARG NEXT_PUBLIC_BBS_ML_URL
21-
ARG NEXT_PUBLIC_ATLAS_ES_VIEW_ID
22-
ARG NEXT_PUBLIC_THUMBNAIL_GENERATION_BASE_URL
23-
ARG NEXT_PUBLIC_KG_INFERENCE_BASE_URL
24-
ARG NEXT_PUBLIC_ENVIRONMENT
25-
ARG CI_COMMIT_SHORT_SHA
26-
ARG NEXT_PUBLIC_VIRTUAL_LAB_API_URL
27-
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
28-
ARG NEXT_PUBLIC_BBS_ML_PRIVATE_BASE_URL
29-
ARG NEXT_PUBLIC_BRAIN_REGION_ONTOLOGY_RESOURCE_TAG
30-
ARG NEXT_PUBLIC_CELL_COMPOSITION_TAG
31-
ARG NEXT_PUBLIC_CELL_SVC_BASE_URL
32-
ARG NEXT_PUBLIC_BLUE_NAAS_URL
14+
FROM node:23-alpine AS builder
15+
16+
ARG DEPLOYMENT_ENV
17+
3318
ENV NODE_OPTIONS="--max_old_space_size=7168"
3419

3520
WORKDIR /app
3621
COPY --from=deps /app/node_modules ./node_modules
3722
COPY . .
3823

24+
# Copy correct .env file according to the deployment environment
25+
RUN cp .deployment-envs/.env.$DEPLOYMENT_ENV .env.production
26+
3927
RUN npm run build
4028

4129

4230
# Production image, copy all the files and run next
43-
FROM node:21-alpine AS runner
31+
FROM node:23-alpine AS runner
4432
WORKDIR /app
4533

46-
ENV NODE_ENV production
34+
ENV NODE_ENV=production
4735

4836
RUN addgroup --system --gid 1001 nodejs
4937
RUN adduser --system --uid 1001 nextjs
@@ -59,6 +47,6 @@ USER nextjs
5947

6048
EXPOSE 8000
6149

62-
ENV PORT 8000
50+
ENV PORT=8000
6351

6452
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)