From 5a1607c1061cec7aef5af83462938740d064ad90 Mon Sep 17 00:00:00 2001 From: Syco21 Date: Fri, 15 May 2026 20:48:35 +0200 Subject: [PATCH] Add Docker, Woodpecker CI/CD, and cleanup - Add Dockerfile and .dockerignore for containerisation - Add .woodpecker.yml pipeline (build + deploy to yugioh network on .101) - Add .gitignore to stop tracking .env; replace with .env.example - Add npm start script - Fix index.js: move versionRoutes require before listen, add /health endpoint - Fix git remote push URLs (were pointing at Dashboard repo) Co-Authored-By: Claude Sonnet 4.6 --- .dockerignore | 3 +++ .env => .env.example | 4 ++-- .gitignore | 2 ++ .woodpecker.yml | 28 ++++++++++++++++++++++++++++ Dockerfile | 7 +++++++ package.json | 1 + src/index.js | 16 +++++++--------- 7 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 .dockerignore rename .env => .env.example (68%) create mode 100644 .gitignore create mode 100644 .woodpecker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ca83ee8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +.env +.git diff --git a/.env b/.env.example similarity index 68% rename from .env rename to .env.example index c198dc9..296b173 100644 --- a/.env +++ b/.env.example @@ -1,7 +1,7 @@ DB_HOST=192.168.178.31 DB_PORT=3306 DB_USER=YuGiOh_API -DB_PASSWORD='b26^c`eqJvOCVS4i3$H2bot;|q0#BtM&' +DB_PASSWORD=your_db_password_here DB_NAME=YuGiOhDB YGOPRO_API_BASE=https://db.ygoprodeck.com/api/v7 -PORT=3000 \ No newline at end of file +PORT=3000 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..37d7e73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +.env diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..9f8dc3b --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,28 @@ +when: + branch: main + event: [push, manual] + +steps: + - name: build + image: docker:cli + volumes: + - /var/run/docker.sock:/var/run/docker.sock + commands: + - docker build -t yugioh-api:latest . + + - name: deploy + image: docker:cli + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /opt/docker/yugioh/.env:/opt/docker/yugioh/.env + commands: + - sed "s/='\(.*\)'$/=\1/; s/=\"\(.*\)\"$/=\1/" /opt/docker/yugioh/.env > /tmp/yugioh-api.env + - docker stop yugioh-api || true + - docker rm yugioh-api || true + - docker network create yugioh || true + - docker run -d + --name yugioh-api + --restart unless-stopped + --network yugioh + --env-file /tmp/yugioh-api.env + yugioh-api:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..41a7de6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:20-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm ci --omit=dev +COPY src/ ./src/ +EXPOSE 3000 +CMD ["node", "src/index.js"] diff --git a/package.json b/package.json index 7492f7d..39ea8c5 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "main": "index.js", "scripts": { + "start": "node src/index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { diff --git a/src/index.js b/src/index.js index 32f47a7..378291a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,28 +1,26 @@ -//index.js const express = require('express'); require('dotenv').config(); const cors = require('cors'); -// Routes const importRoutes = require('./routes/importRoutes'); const collectionRoutes = require('./routes/collectionRoutes'); const exportCardsRoutes = require('./routes/exportCardsRoutes'); -const cardImageRoutes = require('./routes/cardImageRoutes'); // <-- new +const cardImageRoutes = require('./routes/cardImageRoutes'); +const versionRoutes = require('./routes/versionRoutes'); const app = express(); -app.use(cors()); // enable CORS for frontend +app.use(cors()); app.use(express.json()); -// Mount routes +app.get('/health', (_req, res) => res.json({ status: 'ok' })); + app.use('/import', importRoutes); app.use('/collection', collectionRoutes); app.use('/exportCards', exportCardsRoutes); app.use('/cardImage', cardImageRoutes); +app.use('/db-version', versionRoutes); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { - console.log(`Server running on http://localhost:${PORT}`); + console.log(`Server running on port ${PORT}`); }); - -const versionRoutes = require('./routes/versionRoutes'); -app.use('/db-version', versionRoutes); \ No newline at end of file