Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 04-jenkins/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM jenkins/jenkins:lts-jdk21

USER root

# Install docker-cli
RUN apt-get update && apt-get install -y lsb-release zip \
&& curl -fsSLo /etc/apt/keyrings/docker-archive-keyring.asc https://download.docker.com/linux/debian/gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker-archive-keyring.asc] https://download.docker.com/linux/debian $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list \
&& apt-get update && apt-get install -y docker-ce-cli

# Install docker-compose
RUN curl -fsL https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d '"' -f 4 | tee /tmp/compose-version \
&& mkdir -p /usr/lib/docker/cli-plugins \
&& curl -fsSLo /usr/lib/docker/cli-plugins/docker-compose https://github.com/docker/compose/releases/download/$(cat /tmp/compose-version)/docker-compose-$(uname -s)-$(uname -m) \
&& chmod +x /usr/lib/docker/cli-plugins/docker-compose \
&& ln -s /usr/lib/docker/cli-plugins/docker-compose /usr/bin/docker-compose \
&& rm /tmp/compose-version

# Install NodeJS
RUN apt-get update \
&& apt-get install -y ca-certificates curl gnupg \
&& curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs

USER jenkins
22 changes: 22 additions & 0 deletions 04-jenkins/backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dependencies and build outputs
node_modules

dist
coverage

# VCS and editor metadata
.git
.gitignore
.vscode
.idea
.DS_Store

# Logs and local env files
*.log
.env
.env.local
.env.*.local

# Docs and CI files not required to build runtime image
README.md
Jenkinsfile
17 changes: 17 additions & 0 deletions 04-jenkins/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules/
dist/
.DS_Store
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env
.env.local
.env.*.local
.vscode/
.idea/
src/prisma/
*.swp
*.swo
*~
coverage/
9 changes: 9 additions & 0 deletions 04-jenkins/backend/.oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"ignorePatterns": ["src/prisma"],
"printWidth": 150,
"arrowParens": "always",
"semi": true,
"endOfLine": "lf",
"useTabs": false
}
18 changes: 18 additions & 0 deletions 04-jenkins/backend/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": [],
"categories": {},
"rules": {
"prefer-const": "warn"
},
"settings": {
"vitest": {
"typecheck": true
}
},
"env": {
"builtin": true
},
"globals": {},
"ignorePatterns": []
}
25 changes: 25 additions & 0 deletions 04-jenkins/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Stage 1: Build
FROM node:lts AS builder
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
RUN npm run prisma:generate
RUN npm run build

# Stage 2: Production
FROM node:lts

ENV NODE_ENV="production"
WORKDIR /app
EXPOSE 3000

COPY package.json package-lock.json ./
RUN npm ci

COPY --from=builder /app/dist/ dist/

CMD [ "npm", "start" ]

2 changes: 2 additions & 0 deletions 04-jenkins/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


31 changes: 31 additions & 0 deletions 04-jenkins/backend/compose.e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
mongo-e2e:
build:
context: .
dockerfile: mongo.Dockerfile
args:
MONGO_VERSION: 8.2.2
environment:
MONGO_REPLICA_PORT: 27017
MONGO_REPLICA_HOST: mongo-e2e
MONGO_COMMAND: mongosh
healthcheck:
test: ["CMD", "mongosh", "--eval", "rs.status().ok || quit(1)"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s

tests:
build:
context: .
target: builder
environment:
DATABASE_URL: mongodb://mongo-e2e:27017/recipes?replicaSet=rs0
FORCE_COLOR: 0
NO_COLOR: true
TEST_MODE: $TEST_MODE
command: npm run test:e2e
depends_on:
mongo-e2e:
condition: service_healthy
18 changes: 18 additions & 0 deletions 04-jenkins/backend/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
mongo:
build:
context: .
dockerfile: mongo.Dockerfile
args:
MONGO_VERSION: 8.2.2
ports:
- 27017:27017
environment:
MONGO_REPLICA_PORT: 27017
MONGO_REPLICA_HOST: localhost
MONGO_COMMAND: mongosh
volumes:
- mongo_data:/data/db

volumes:
mongo_data:
14 changes: 14 additions & 0 deletions 04-jenkins/backend/mongo.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# See: https://github.com/prisma/prisma/blob/main/docker/docker-compose.yml
ARG MONGO_VERSION

FROM mongo:${MONGO_VERSION}

# we take over the default & start mongo in replica set mode in a background task
ENTRYPOINT mongod --port $MONGO_REPLICA_PORT --replSet rs0 --bind_ip 0.0.0.0 & MONGOD_PID=$!; \
# we prepare the replica set with a single node and prepare the root user config
INIT_REPL_CMD="rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: '$MONGO_REPLICA_HOST:$MONGO_REPLICA_PORT' }] })"; \
# we wait for the replica set to be ready and then submit the command just above
until ($MONGO_COMMAND admin --port $MONGO_REPLICA_PORT --eval "$INIT_REPL_CMD"); do sleep 1; done; \
# we are done but we keep the container by waiting on signals from the mongo task
echo "REPLICA SET ONLINE"; wait $MONGOD_PID;
6 changes: 6 additions & 0 deletions 04-jenkins/backend/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src", "generated"],
"ext": "ts",
"ignore": ["src/**/*.test.ts", "src/**/*.spec.ts"],
"exec": "tsx ./src/server.ts"
}
Loading