-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/dockerize app #47
base: main
Are you sure you want to change the base?
Changes from all commits
9288877
5c7d93f
5531927
565c269
d2b1c4b
4dba93c
63010d2
cd7ac6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Node modules | ||
node_modules | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Environment variables | ||
.env | ||
.env.* | ||
|
||
# Docker files | ||
Dockerfile | ||
docker-compose.yml | ||
.dockerignore | ||
|
||
# Git files | ||
.git | ||
.gitignore | ||
|
||
# Others | ||
dist | ||
coverage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
NODE_ENV=development | ||
|
||
PORT=3000 | ||
|
||
DATABASE_URL="postgresql://postgres@localhost:5432/planifetsDB?schema=public" | ||
# Database Configuration | ||
DATABASE_URL="postgresql://postgres@localhost:5433/planifetsDB?schema=public" | ||
POSTGRES_HOST="db" | ||
POSTGRES_DB="planifetsDB" | ||
POSTGRES_PASSWORD="postgres" | ||
POSTGRES_USER="postgres" | ||
POSTGRES_PORT=5433 | ||
|
||
LOG_LEVELS="log,error,warn,debug" # Log levels: "log,error,warn,debug,fatal,verbose" | ||
# Logging Levels | ||
LOG_LEVELS="log,error,warn,debug" # Options: log,error,warn,debug,fatal,verbose |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: CD | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*' | ||
pull_request: # fixme: test purpose only | ||
branches: ['main'] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'yarn' | ||
cache-dependency-path: 'yarn.lock' | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: yarn run test | ||
|
||
- name: Build project | ||
run: yarn run build | ||
|
||
docker: | ||
runs-on: ubuntu-latest | ||
needs: [build-and-test] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Docker meta | ||
# if: github.event_name != 'pull_request' | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
|
||
- name: Login to Registry | ||
# if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true # ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
semantic-release: | ||
runs-on: ubuntu-latest | ||
needs: [docker] | ||
steps: | ||
- name: Semantic Release | ||
uses: cycjimmy/semantic-release-action@v4 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# Base dependencies | ||
FROM node:18-alpine AS base | ||
WORKDIR /app | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install | ||
|
||
# Development | ||
FROM base AS development | ||
WORKDIR /app | ||
COPY . ./ | ||
|
||
RUN yarn install --frozen-lockfile && yarn global add @nestjs/cli && yarn prisma:generate | ||
|
||
ENV NODE_ENV=development | ||
# Required for hot-reloading | ||
ENV CHOKIDAR_USEPOLLING=true | ||
|
||
CMD [ "yarn", "start:dev" ] | ||
|
||
# Build | ||
FROM base AS build | ||
WORKDIR /app | ||
COPY . ./ | ||
|
||
RUN yarn build | ||
|
||
# Production | ||
FROM node:18-alpine AS production | ||
WORKDIR /app | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install --production --frozen-lockfile | ||
|
||
COPY --from=build /app/dist ./dist | ||
COPY prisma ./prisma | ||
RUN yarn prisma:generate | ||
|
||
ENV NODE_ENV=production | ||
|
||
CMD [ "yarn", "start:prod" ] | ||
|
||
EXPOSE 3000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v2 | ||
name: planifets-backend | ||
description: A Helm chart for Kubernetes | ||
type: application | ||
version: 0.2.0 | ||
appVersion: '0.1.0' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: "{{ .Release.Name }}-{{ .Chart.Name }}" | ||
labels: | ||
app: "{{ .Chart.Name }}" | ||
spec: | ||
replicas: {{ .Values.replicaCount }} | ||
selector: | ||
matchLabels: | ||
app: "{{ .Chart.Name }}" | ||
template: | ||
metadata: | ||
labels: | ||
app: "{{ .Chart.Name }}" | ||
spec: | ||
containers: | ||
- name: app | ||
Check warning Code scanning / SonarCloud Memory limits should be enforced Medium
Specify a memory limit for this container. See more on SonarCloud
Check warning Code scanning / SonarCloud Storage limits should be enforced Medium
Specify a storage limit for this container. See more on SonarCloud
|
||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" | ||
ports: | ||
- containerPort: {{ .Values.service.port }} | ||
env: | ||
- name: DATABASE_URL | ||
valueFrom: | ||
secretKeyRef: | ||
name: "{{ .Values.postgresSecretName }}" | ||
key: DATABASE_URL | ||
- name: NODE_ENV | ||
value: production | ||
- name: PORT | ||
value: "{{ .Values.service.port }}" | ||
livenessProbe: | ||
httpGet: | ||
path: / | ||
port: {{ .Values.service.port }} | ||
initialDelaySeconds: 15 | ||
periodSeconds: 20 | ||
readinessProbe: | ||
httpGet: | ||
path: / | ||
port: {{ .Values.service.port }} | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: "{{ .Release.Name }}-{{ .Chart.Name }}-service" | ||
spec: | ||
selector: | ||
app: "{{ .Chart.Name }}" | ||
ports: | ||
- protocol: TCP | ||
port: {{ .Values.service.port }} | ||
targetPort: {{ .Values.service.port }} | ||
type: {{ .Values.service.type }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: "{{ .Release.Name }}-{{ .Chart.Name }}-ingress" | ||
spec: | ||
ingressClassName: nginx | ||
rules: | ||
- host: {{ (index .Values.ingress.hosts 0).host }} | ||
http: | ||
paths: | ||
- path: / | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: "{{ .Release.Name }}-{{ .Chart.Name }}-service" | ||
port: | ||
number: {{ .Values.service.port }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: postgres-pvc | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi # todo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ .Values.postgresSecretName }} | ||
type: Opaque | ||
stringData: | ||
POSTGRES_USER: {{ .Values.postgres.user }} | ||
POSTGRES_PASSWORD: {{ .Values.postgres.password }} | ||
POSTGRES_DB: {{ .Values.postgres.db }} | ||
DATABASE_URL: "postgresql://{{ .Values.postgres.user }}:{{ .Values.postgres.password }}@postgres:5432/{{ .Values.postgres.db }}?schema=public" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: postgres | ||
labels: | ||
app: postgres | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: postgres | ||
template: | ||
metadata: | ||
labels: | ||
app: postgres | ||
spec: | ||
containers: | ||
Check warning Code scanning / SonarCloud Service account permissions should be restricted Medium
Bind this resource's automounted service account to RBAC or disable automounting. See more on SonarCloud
|
||
- name: postgres | ||
Check warning Code scanning / SonarCloud Memory limits should be enforced Medium
Specify a memory limit for this container. See more on SonarCloud
Check warning Code scanning / SonarCloud Storage limits should be enforced Medium
Specify a storage limit for this container. See more on SonarCloud
|
||
image: postgres:16 | ||
ports: | ||
- containerPort: 5432 | ||
env: | ||
- name: POSTGRES_USER | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Values.postgresSecretName }} | ||
key: POSTGRES_USER | ||
- name: POSTGRES_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Values.postgresSecretName }} | ||
key: POSTGRES_PASSWORD | ||
- name: POSTGRES_DB | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Values.postgresSecretName }} | ||
key: POSTGRES_DB | ||
volumeMounts: | ||
- name: postgres-storage | ||
mountPath: /var/lib/postgresql/data | ||
livenessProbe: | ||
exec: | ||
command: | ||
- pg_isready | ||
- -U | ||
- {{ .Values.postgres.user }} | ||
initialDelaySeconds: 30 | ||
periodSeconds: 10 | ||
readinessProbe: | ||
exec: | ||
command: | ||
- pg_isready | ||
- -U | ||
- {{ .Values.postgres.user }} | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
volumes: | ||
- name: postgres-storage | ||
persistentVolumeClaim: | ||
claimName: postgres-pvc | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: postgres | ||
spec: | ||
selector: | ||
app: postgres | ||
ports: | ||
- port: 5432 | ||
targetPort: 5432 | ||
protocol: TCP | ||
type: ClusterIP |
Check warning
Code scanning / SonarCloud
Service account permissions should be restricted Medium