Skip to content

Commit

Permalink
Merge pull request #11 from geoblocks/docker-image
Browse files Browse the repository at this point in the history
feat: Docker image
  • Loading branch information
tyrossel authored Oct 21, 2024
2 parents 5ae1051 + 89bb03e commit c9905a0
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules/
.*-cache/
.*_cache/

dist/
Dockerfile
.dockerignore
docker-compose.yml

3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Choose an app to display.
# If none is selected, the list of apps will be displayed.
# APP_NAME=permits
59 changes: 59 additions & 0 deletions .github/workflows/publish_docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish docker image

on:
workflow_run:
workflows: ['CI']
branches: [main]
types:
- completed

permissions:
contents: read
packages: write

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMG_NAME: geoblocks/ngv-ui
DOCKER_TAG: latest

jobs:
build_and_publish:
name: Build and publish
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: DOCKER_REGISTRY
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ngv
uses: docker/build-push-action@v6
with:
push: true
tags: ${DOCKER_REGISTRY}/${DOCKER_IMG_NAME:${DOCKER_TAG}
- name: Update images sha
run: echo "img_sha=$(docker inspect --format='{{index .RepoDigests 0}}' '${DOCKER_REGISTRY}/${DOCKER_IMG_NAME}:${DOCKER_TAG}' | cut -d':' -f2)" >> $GITHUB_ENV;

trigger_deploy:
name: Trigger deploy on lab
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
needs: build_and_publish
steps:
- name: Deploy Stage
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_PAT_DEPLOY }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'camptocamp',
repo: 'argocd-gs-plg-apps',
workflow_id: 'update-ngv-image.yaml',
ref: 'main'
inputs: {
environment: prod
img_sha: $img_sha
}
});
17 changes: 17 additions & 0 deletions .github/workflows/registry_cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: GitHub Container Registry cleanup

on:
schedule:
- cron: '34 3 8 * *' # Every night the first of the month

jobs:
cleanup:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/delete-package-versions@v5
with:
package-name: 'ngv-ui'
package-type: 'container'
min-versions-to-keep: 5
delete-only-untagged-versions: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
lib/
dist/
.env
31 changes: 24 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# A dockerfile is provided
FROM debian:bookworm-slim AS builder

# It is based on a stable distro, example debian

# It produces several images:
# - frontend: contains all apps frontends, served by nginx;
# - backend: contains all apps backends, served by node or deno.
WORKDIR /app

# An entrypoint allows to select the active app.
RUN apt-get update && apt-get -y install --no-install-recommends \
npm

# The images are published to docker hub.
COPY package.json package-lock.json /app/
RUN npm ci

COPY . /app/
RUN npm run build # && npm run doc

FROM nginxinc/nginx-unprivileged:1.27-bookworm-perl AS server

LABEL org.opencontainers.image.source="https://github.com/geoblocks/ngv"

COPY --from=builder /app/dist /usr/share/nginx/html

# The nginx.conf.template file is used to configure the nginx server.
# In the entrypoint, the environment variables are automatically replaced.
# See docs for more information: https://hub.docker.com/_/nginx
COPY docker/*.conf.template /etc/nginx/templates/

# Hooks for the entrypoint
# env files are executed, envsh files are sourced
COPY docker/*.envsh docker/*.sh /docker-entrypoint.d/
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
services:
viewer:
build:
context: .
env_file: .env
ports:
- 8080:8080
15 changes: 15 additions & 0 deletions docker/14-ngv.envsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env bash
# This file will be sourced in the container before running the env substitution in the container.

APP_NAME="${APP_NAME:-all}"

case "$APP_NAME" in
"") ;;
"/") ;;
"all") ;;
*) export APP_PATH="src/apps/${APP_NAME}" ;;
esac

entrypoint_log "APP_PATH=$APP_PATH"

export APP_PATH
26 changes: 26 additions & 0 deletions docker/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Nginx config file
#

server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html/;
access_log off;
index index.html;

add_header 'Access-Control-Allow-Origin' '*' always;
expires 4h;

gzip on;

gzip_types application/javascript text/css application/json;


location / {
# root and alias cannot be use here, because we need to access common files at the root
index $APP_PATH/index.html;
try_files $uri $uri/ =404;
expires -1;
}

}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"prettier": "prettier . --check",
"prettier-fix": "prettier -w .",
"typing": "tsc --noEmit",
"prepare": "tsc",
"api-extractor": "api-extractor run --local --verbose --typescript-compiler-folder node_modules/typescript",
"api-extractor-check": "api-extractor run --verbose --typescript-compiler-folder node_modules/typescript",
"api-documenter": "api-documenter markdown -i temp/ -o docs",
Expand Down

0 comments on commit c9905a0

Please sign in to comment.