Skip to content

Commit

Permalink
Merge pull request #34 from IGNF/4-mise-en-place-du-projet-de-dévelop…
Browse files Browse the repository at this point in the history
…pement-et-dockerisation

ajout dockerisation et publication automatisée des realeases
  • Loading branch information
cdebarros authored Jan 17, 2025
2 parents 2dd42ed + 46cc98b commit 5c7b3e3
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .docker/nginx.apps.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
server {
listen 8000;
listen [::]:8000;
server_name localhost;

root /usr/share/nginx/html;

server_tokens off;

location ~ /index.html|.*\.toml|.*\.json$ {
expires -1;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}

location ~ .*\.css$|.*\.js$ {
add_header Cache-Control 'max-age=86400'; # 24h
}

location ~ .*\.otf$|.*\.ttf$|.*\.woff2?$ {
add_header Cache-Control 'max-age=31536000'; # 1year
}

location / {
try_files $uri $uri/ /index.html;

add_header Cache-Control 'max-age=86400'; # 24h
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

77 changes: 77 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
pull: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG registry=docker.io
FROM ${registry}/library/node:18-slim as nodebuild

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN apt-get update
RUN npm install -g npm
RUN npm install -g @angular/[email protected]

RUN mkdir /opt/cartosp && chown -R node:node /opt/cartosp
WORKDIR /opt/cartosp
COPY . .
RUN npm install
RUN ng build
RUN chown -R node /opt/cartosp/dist/cartosp/browser
USER node

FROM ${registry}/nginxinc/nginx-unprivileged:stable

# USER 101
COPY --from=nodebuild /opt/cartosp/dist/cartosp/browser/ /usr/share/nginx/html
COPY .docker/nginx.apps.conf /etc/nginx/conf.d/default.conf
14 changes: 12 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,25 @@
],
"scripts": [
"./node_modules/@gouvfr/dsfr/dist/dsfr/dsfr.module.js"
],
"allowedCommonJsDependencies": [
"lodash",
"rbush",
"pbf",
"loglevel",
"eventbusjs",
"node-fetch",
"es6-promise",
"@xmldom/xmldom"
]
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumWarning": "5mb",
"maximumError": "10mb"
},
{
"type": "anyComponentStyle",
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:

site:
image: cartosp
build:
context: .
dockerfile: Dockerfile
args:
- http_proxy
- https_proxy
ports:
- "8000:8000"
restart: unless-stopped

0 comments on commit 5c7b3e3

Please sign in to comment.