Skip to content

Commit

Permalink
build(docker): dockerisation et publication sur ghcr
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Feb 12, 2024
1 parent 198cf29 commit fe6339d
Show file tree
Hide file tree
Showing 7 changed files with 5,025 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#----------------------------------------------------------------------
# cartesgouvfr-documentation : Génération d'un build statique
#----------------------------------------------------------------------
FROM node:18-alpine as builder

RUN apk add git

WORKDIR /app
COPY . .
RUN npm ci \
&& npx @11ty/eleventy \
&& rm -rf node_modules .git

#----------------------------------------------------------------------
# cartesgouvfr-documentation : Config d'un serveur statique avec nginx
#----------------------------------------------------------------------
FROM nginx:alpine
COPY --from=builder /app/_site /usr/share/nginx/html/
COPY .docker/nginx.conf /etc/nginx/nginx.conf

EXPOSE 8082
48 changes: 48 additions & 0 deletions .docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

server {
listen 8082;
listen [::]:8082;
server_name localhost;
resolver 127.0.0.11;
autoindex off;

server_name _;
server_tokens off;

root /usr/share/nginx/html; # Path to your static files
gzip_static on;

index index.html index.htm;

# Redirect "/" to "/fr"
location = / {
return 301 /fr;
}

# Serve static files
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /404.html;
}

# Handle 404 errors
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
internal;
}
}
}
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.vscode
/node_modules/
/docs
/_site

compose*.yml
renovate.json
6 changes: 3 additions & 3 deletions .github/workflows/11ty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ concurrency:
cancel-in-progress: false

jobs:
# Build job
build:
name: Generate a static build
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -43,8 +43,8 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v3

# Deployment job
deploy:
deploy-ghpages:
name: Deploy to github pages
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Docker build & publish

on:
push:
# Publish semver tags as releases.
tags: ["v*.*.*"]

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

jobs:
deploy-ghcr:
name: Deploy to ghcr
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: build

steps:
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
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
# https://github.com/docker/build-push-action
- name: Build and push Docker image to ghcr
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
file: .docker/Dockerfile
pull: true
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
19 changes: 19 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.8"

services:
site:
image: ignf/cartes.gouv.fr-documentation
build:
context: .
dockerfile: ".docker/Dockerfile"
args:
- HTTP_PROXY
- HTTPS_PROXY
ports:
- 8082:8082
environment:
- HTTP_PROXY=${HTTP_PROXY}
- HTTPS_PROXY=${HTTPS_PROXY}
- http_proxy=${HTTP_PROXY}
- https_proxy=${HTTPS_PROXY}
restart: unless-stopped
Loading

0 comments on commit fe6339d

Please sign in to comment.