From 5679ea30d2f545497ad64655389f439c6c4f03dd Mon Sep 17 00:00:00 2001 From: Puechberty Arthur Date: Thu, 11 Jun 2026 01:06:48 +0200 Subject: [PATCH] update runner --- .env.example | 12 ++++++++-- .github/workflows/deploy.yml | 43 ++++++++++++------------------------ Dockerfile | 25 +++++++++++++++++++++ docker-compose.yml | 31 ++++++++++++++++---------- 4 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 Dockerfile diff --git a/.env.example b/.env.example index 3fef639..f898ab8 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,12 @@ -ADMIN_USERNAME=change-me +ADMIN_USERNAME=admin ADMIN_PASSWORD=change-me ADMIN_SESSION_SECRET=replace-with-a-long-random-secret -PORT=3000 + +# Port exposé côté machine +APP_PORT=3000 + +# Node environment +NODE_ENV=production + +# Next.js +PORT=3000 \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0b20345..ffbc61b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,42 +1,27 @@ -name: Deploy to VM Prod +name: Deploy Docker on: push: - branches: - - main + branches: ["main"] jobs: deploy: runs-on: self-hosted + steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Deploy to production + - name: Deploy on server run: | - REPO_NAME=${{ github.event.repository.name }} + set -e - if [ -z "${{ secrets.ENV_FILE }}" ]; then - ENV_CONTENT="" - else - ENV_CONTENT="${{ secrets.ENV_FILE }}" - fi + echo "Go to app folder" + cd /opt/apps/links - ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} " - mkdir -p /srv/$REPO_NAME - cd /srv/$REPO_NAME + echo "Pull latest code" + git pull origin main - if [ ! -d .git ]; then - rm -rf ./* # vide le dossier si nécessaire - git clone https://github.com/arthur-pbty-labs/$REPO_NAME . - else - git reset --hard - git pull origin main - fi + echo "Build & restart containers" + docker compose down || true + docker compose build + docker compose up -d - if [ -n \"$ENV_CONTENT\" ]; then - echo \"$ENV_CONTENT\" > .env - fi - - docker compose up -d --build - " + echo "Deploy finished" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..def5173 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# ===== BUILD ===== +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci + +COPY . . + +RUN npm run build + + +# ===== RUN ===== +FROM node:20-alpine AS runner + +WORKDIR /app + +ENV NODE_ENV=production + +COPY --from=builder /app ./ + +EXPOSE 3000 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 581464b..3092047 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,22 @@ services: - app: - image: node:20 - working_dir: /usr/src/app - volumes: - - ./:/usr/src/app + links: + build: + context: . + dockerfile: Dockerfile + + container_name: links + ports: - - "3000:3000" + - "${APP_PORT}:3000" + + env_file: + - .env + restart: unless-stopped - environment: - - PORT=${PORT:-3000} - - ADMIN_USERNAME=${ADMIN_USERNAME} - - ADMIN_PASSWORD=${ADMIN_PASSWORD} - - ADMIN_SESSION_SECRET=${ADMIN_SESSION_SECRET} - command: sh -c "npm install && npm run build && npm start" \ No newline at end of file + + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000/"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s \ No newline at end of file