Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
dist
dist-demo
.git
.github
.changeset
.eslintcache
*.log
packages/web-forms/src/demo/server/node_modules
180 changes: 180 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
---
name: Docker Build & Push

on: # yamllint disable-line rule:truthy
push:
branches: [ona-app]
pull_request:
branches: [ona-app]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

env:
ECR_REGISTRY: 447036922786.dkr.ecr.eu-central-1.amazonaws.com
ECR_REPOSITORY: onaio/webforms
AWS_REGION: eu-central-1

jobs:
build:
strategy:
fail-fast: false
matrix:
platforms:
- [linux/amd64, ubuntu-latest]
- [linux/arm64, ubuntu-24.04-arm]
runs-on: ${{ matrix.platforms[1] }}
permissions:
contents: read
outputs:
image-tag: ${{ steps.tags.outputs.tag }}

steps:
- name: Prepare
run: |
platform=${{ matrix.platforms[0] }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

- uses: actions/checkout@v6

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2

- name: Set image tags
id: tags
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BRANCH=$(echo "${{ github.head_ref }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)
echo "tag=${BRANCH}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "is_main=false" >> "$GITHUB_OUTPUT"
else
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
BRANCH=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
echo "tag=${BRANCH}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "is_main=true" >> "$GITHUB_OUTPUT"
fi

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}
tags: |
type=raw,value=${{ steps.tags.outputs.tag }}
type=raw,value=${{ steps.tags.outputs.branch }}

- name: Build and push by digest
id: docker-build
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platforms[0] }}
cache-from: type=gha,scope=${{ env.PLATFORM_PAIR }}
cache-to: type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
outputs: >
type=image,
name=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }},
push-by-digest=true,
name-canonical=true,
push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.docker-build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
outputs:
image-tag: ${{ needs.build.outputs.image-tag }}

steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2

- name: Set image tags
id: tags
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BRANCH=$(echo "${{ github.head_ref }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)
echo "tag=${BRANCH}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "is_main=false" >> "$GITHUB_OUTPUT"
else
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
BRANCH=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
echo "tag=${BRANCH}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "is_main=true" >> "$GITHUB_OUTPUT"
fi

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}
tags: |
type=raw,value=${{ steps.tags.outputs.tag }}
type=raw,value=${{ steps.tags.outputs.branch }}
${{ steps.tags.outputs.is_main == 'true' && 'type=raw,value=latest' || '' }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}@sha256:%s ' *)

- name: Inspect image
run: |
docker buildx imagetools inspect \
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ steps.tags.outputs.tag }}
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:24-alpine AS build

WORKDIR /app

COPY package.json package-lock.json .npmrc turbo.json tsconfig.json tsconfig.vendor-types.json tsconfig.tools.json ./
COPY packages/ packages/

RUN npm ci

RUN npx turbo run build --filter=@getodk/xforms-engine \
&& npm run build:demo --workspace=@getodk/web-forms

FROM node:24-alpine

WORKDIR /app

COPY packages/web-forms/src/demo/server/ ./server/
RUN cd server && npm ci --omit=dev

COPY --from=build /app/packages/web-forms/dist-demo/ ./dist-demo/

EXPOSE 8005
ENV PORT=8005

CMD ["node", "server/index.mjs"]
Loading
Loading