Matteo Bonneval Toolbox

website·Indexed 29 days ago

http://toolbox.matteo-bonneval.fr

A collection of templates for Docker images and GitLab CI/CD pipelines. Includes production-ready Dockerfiles for Nuxt, Vue.js, React, Express, NestJS, Flask, and FastAPI, as well as GitLab pipeline templates for automated building, testing, and deployment, and Caddy reverse proxy installation guides.

Tokens
4.6K
Snippets
39
Records
42
Agent score
50%

What's inside Matteo Bonneval Toolbox

  1. Accelerate development with project starters

    Ready-to-use project starters are available for frameworks such as Symfony, Nuxt, and Express, allowing developers to begin coding immediately without manual initial configuration.
  2. Use pre-configured Docker images for common frameworks

    Pre-made Docker images are available for various technology stacks to reduce setup time, including Symfony, React, VueJS, Nuxt, and Express.
  3. Use pre-made GitLab CI/CD pipeline templates

    The toolbox provides pre-configured GitLab CI/CD pipeline templates to streamline project tasks such as deployment, testing, and building.
  4. Create a multi-stage Dockerfile for a React app with Nginx

    Use a multi-stage Dockerfile to build a React application and serve it via Nginx. The first stage (build) uses node:20-alpine to install dependencies and build the project. The second stage (production) uses nginx:stable-alpine to serve the static files from the /app/build directory, exposing port 80.
    FROM node:20-alpine AS build
    WORKDIR /app
    COPY package*.json ./
    RUN npm install
    
    COPY . . 
    RUN npm run build
     
    # Production Stage
    FROM nginx:stable-alpine AS production
    COPY --from=build /app/build /usr/share/nginx/html
    EXPOSE 80
    
    CMD ["nginx", "-g", "daemon off;"]
  5. Create a Dockerfile for an Express.js application

    Use a lightweight Node.js 20 Alpine image to containerize an Express app. This configuration includes the installation of necessary system dependencies (openssl and musl) and sets up the working directory and dependency installation before copying the application source code.
    FROM node:20-alpine
    
    # Add necessary dependencies
    RUN apk add --no-cache openssl musl
    
    WORKDIR /app
    
    COPY package.json .
    RUN npm install
    
    COPY . .
    
    # Replace server.js with the name of your main entry file
    CMD ["node", "server.js"]
  6. Dockerize a Nuxt application for production

    Use a multi-stage Docker build to create a lightweight production image for Nuxt. The process involves a 'base' stage for the Node environment, a 'build' stage to install dependencies and compile the application, and a final runtime stage that only copies the .output directory to minimize image size.
    ARG NODE_VERSION=20.18.0
    FROM node:${NODE_VERSION}-slim as base
    
    ARG PORT=3000
    
    WORKDIR /src
    
    # Build
    FROM base as build
    COPY --link package.json package-lock.json .
    RUN npm install
    
    COPY --link .. .
    
    RUN npm run build
    
    # Run
    FROM base
    ENV PORT=$PORT
    ENV NODE_ENV=production
    COPY --from=build /src/.output /src/.output
    
    CMD [ "node", ".output/server/index.mjs" ]
  7. Create a Dockerfile for a FastAPI application

    To containerize a FastAPI application, use a Python 3.12 base image. The application requires uvicorn to be installed and a requirements.txt file to be present in the root directory. The container exposes port 80 and starts the application using Uvicorn, targeting the app.main:app entry point.
    FROM python:3.12
    WORKDIR /app
    
    COPY . /app
    RUN pip install --no-cache-dir -r requirements.txt
    
    EXPOSE 80
    CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
  8. Prepare the server for Docker Swarm deployment

    Before running the pipeline, perform the following manual setup on the server:

    1. Create a directory for your project and add a compose.yaml file defining your services.
    2. Authenticate the server with the GitLab registry to allow image pulling.
    3. Pre-pull the required images.
    4. Deploy the stack for the first time to establish the service name.
    5. Identify the service name using docker service ls to use it in the deployment script.
    # Authenticate with GitLab Registry
    docker login -u [user_gitlab] -p [password_gitlab] registry.gitlab.com
    
    # Pre-pull image
    docker pull registry.gitlab.com/[username]/[image]:latest
    
    # Initial stack deployment
    docker stack deploy -c compose.yaml [STACK_NAME]
    
    # Verify service name
    docker service ls
  9. Configure the GitLab CI/CD pipeline for Docker Swarm deployment

    Add a deploy stage to your .gitlab-ci.yml file. The pipeline uses an Alpine image to install an SSH client, decodes the base64 private key, and executes the deploy.sh script on the remote server. This job is configured to run only on the main branch.
    stages:
      - build
      - deploy
    
    variables:
      PATH_DEPLOY: [PATH_TO_DEPLOY_SH_FOLDER]
    
    deploy:
      stage: deploy
      image: alpine:latest
      only:
        - main
      script:
        - apk add --no-cache openssh-client
        - mkdir -p ~/.ssh
        - echo ${SSH_PRIVATE_KEY} | base64 -d > ~/.ssh/id_rsa
        - chmod 600 ~/.ssh/id_rsa
        - ssh-keygen -l -f ~/.ssh/id_rsa
        - ssh -o StrictHostKeyChecking=no ${USER_SERVE}@${IP_SERVE} "cd ${PATH_DEPLOY}/ && ./deploy.sh"
  10. Install Caddy on Debian, Ubuntu, or Raspbian

    Caddy provides a reverse proxy solution with automatic HTTPS implementation. To install Caddy on Debian-based systems, add the official Cloudsmith repository and install the package via apt.
    sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
    sudo apt update
    sudo apt install caddy