setup dockerfile readme and docker compose (#15)
Docker File backend, docker compose
This commit is contained in:
parent
7ca07d6c69
commit
7d78721763
1
.gitignore
vendored
1
.gitignore
vendored
@ -49,3 +49,4 @@ cabal.project.local
|
||||
cabal.project.local~
|
||||
.HTF/
|
||||
.ghc.environment.*
|
||||
id_rsa
|
||||
|
@ -5,8 +5,14 @@ WORKDIR leCoffre
|
||||
|
||||
RUN npm install -D prisma@4.11.0
|
||||
COPY package.json ./
|
||||
COPY src/common/databases/schema.prisma ./src/common/databases/schema.prisma
|
||||
RUN npx prisma generate
|
||||
|
||||
RUN apk update && apk add openssh-client git
|
||||
|
||||
COPY id_rsa /root/.ssh/id_rsa
|
||||
RUN chmod 600 ~/.ssh/id_rsa
|
||||
RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa
|
||||
RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /root/.ssh/known_hosts
|
||||
|
||||
RUN npm install --frozen-lockfile
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
@ -14,16 +20,12 @@ FROM node:19-alpine AS builder
|
||||
|
||||
WORKDIR leCoffre
|
||||
|
||||
COPY . .
|
||||
COPY --from=deps leCoffre/node_modules ./node_modules
|
||||
COPY --from=deps leCoffre/package.json package.json
|
||||
COPY tsconfig.json tsconfig.json
|
||||
COPY src src
|
||||
|
||||
RUN apk update && apk add openssh-client git
|
||||
|
||||
COPY id_ed25519 /root/.ssh/id_ed25519
|
||||
RUN chmod 600 ~/.ssh/id_ed25519
|
||||
RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_ed25519
|
||||
RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /root/.ssh/known_hosts
|
||||
|
||||
COPY node_modules ./node_modules
|
||||
COPY src/common/databases/schema.prisma ./src/common/databases/schema.prisma
|
||||
RUN npx prisma generate
|
||||
RUN npm run build
|
||||
|
||||
@ -35,10 +37,7 @@ WORKDIR leCoffre
|
||||
RUN adduser -D lecoffreuser --uid 10000 && chown -R lecoffreuser .
|
||||
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/node_modules ./node_modules
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/dist/api ./dist/api
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/dist/entries ./dist/entries
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/dist/common ./dist/common
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/src/common/databases/ ./src/common/databases/
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/dist dist
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/package.json ./package.json
|
||||
|
||||
USER lecoffreuser
|
||||
|
34
README.md
34
README.md
@ -1,2 +1,36 @@
|
||||
# leCoffre
|
||||
[Owner: Elise Hautefaye]
|
||||
|
||||
### A. Docker Launch application
|
||||
#### 1) Local RSA Key for docker build
|
||||
|
||||
1) Create a file named : `id_rsa` in /src
|
||||
2) Get the RSA Private key on Keeper who is allowed to read the `leCoffre-ressources repo`
|
||||
3) You can find Key on Keeper inside the folder **LeCoffre project > SSH Key**
|
||||
4) Copy past in the `id_rsa` that you created step 1
|
||||
|
||||
:rotating_light: **Be aware to have the id_rsa included in your .gitignore! This ssh shouldn't be push on github**
|
||||
|
||||
> You need to do the same task in the front and back repo.
|
||||
|
||||
#### 2) Build images
|
||||
|
||||
###### a- Back end
|
||||
`docker build -t "le-coffre-back" -f Dockerfiles/Dockerfile.api .`
|
||||
###### b- Front end
|
||||
`docker build -t "le-coffre-front" -f Dockerfiles/Dockerfile.front .`
|
||||
|
||||
#### 3) Docker Run
|
||||
|
||||
`docker run --env-file .env -p 3000:3000 le-coffre-back`
|
||||
|
||||
#### 4) Docker Compose
|
||||
|
||||
Docker compose allow to launch multiples images
|
||||
1) **le-coffre-front**
|
||||
2) **le-coffre-back**
|
||||
3) **postgres**
|
||||
|
||||
> Launch your docker container with following command :
|
||||
|
||||
`docker compose up -d`
|
@ -4,16 +4,38 @@ volumes:
|
||||
db_storage:
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: lecoffrelocal
|
||||
restart: always
|
||||
front-end:
|
||||
image: "le-coffre-front"
|
||||
ports:
|
||||
- 3000:${FRONT_PORT}
|
||||
environment:
|
||||
- POSTGRES_USER
|
||||
- POSTGRES_PASSWORD
|
||||
- POSTGRES_DB
|
||||
- DATABASE_USERNAME
|
||||
- FRONT_PORT
|
||||
backend:
|
||||
image: "le-coffre-back"
|
||||
ports:
|
||||
- 3001:${APP_PORT}
|
||||
environment:
|
||||
- DATABASE_HOSTNAME
|
||||
- DATABASE_PORT
|
||||
- DATABASE_USER
|
||||
- DATABASE_PASSWORD
|
||||
- DATABASE_NAME
|
||||
- APP_LABEL
|
||||
- APP_PORT
|
||||
- APP_ROOT_URL
|
||||
- API_ROOT_URL
|
||||
- DEV_PRISMA_STUDIO_DB_URL
|
||||
|
||||
postgres:
|
||||
image: postgres
|
||||
restart: always
|
||||
environment:
|
||||
- DATABASE_HOSTNAME
|
||||
- DATABASE_PORT
|
||||
- DATABASE_USER
|
||||
- DATABASE_PASSWORD
|
||||
- DATABASE_NAME
|
||||
- POSTGRES_PASSWORD
|
||||
ports:
|
||||
- ${DATABASE_PORT}:5432
|
||||
volumes:
|
||||
@ -21,7 +43,7 @@ services:
|
||||
- ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
test: ["CMD-SHELL", "pg_isready -h localhost -U ${DATABASE_USER} -d ${DATABASE_NAME}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
@ -17,13 +17,13 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"api:start": "node ./dist/entries/App.js",
|
||||
"api:start": "npm run migrate && node ./dist/entries/App.js",
|
||||
"start": "tsc && npm run api:start",
|
||||
"dev": "nodemon -V",
|
||||
"api:dev": "nodemon -V --exec 'tsc && npm run api:start'",
|
||||
"build:test": "tsc && mocha ./dist/entries/Test.js",
|
||||
"format": "prettier --write src",
|
||||
"migrate": ""
|
||||
"migrate": "npx prisma migrate deploy"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
Loading…
x
Reference in New Issue
Block a user