Skip to content

Commit

Permalink
improve deployment stage time execution + prevent loosing data in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
dlavaury committed Feb 1, 2024
1 parent ebe3767 commit ec65d65
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
32 changes: 28 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
# Dockerfile server
FROM node:16.14
#syntax=docker/dockerfile:1.4
FROM node:20-alpine

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# hadolint ignore=DL3018
RUN apk add --no-cache libc6-compat

WORKDIR /usr/src/app

COPY ./ .
RUN corepack enable && \
corepack prepare --activate pnpm@latest && \
pnpm config -g set store-dir /.pnpm-store

COPY --link ./server/package.json ./server/
COPY --link ./client/package.json ./client/

RUN cd client && \
pnpm fetch && \
pnpm install
RUN cd server && \
pnpm fetch && \
pnpm install

COPY ./client ./client

RUN cd client && \
pnpm run build

COPY ./server ./server
COPY docker-entry.sh .

RUN npm install
CMD ["sh","./docker-entry.sh"]
4 changes: 0 additions & 4 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ services:
web:
build: .
container_name: ${PROJECT_NAME:-project}-web
volumes:
- .:/var/www
- ./docker-entry.sh:/etc/entrypoint.sh
entrypoint: ["sh", "/etc/entrypoint.sh"]
env_file:
- ../envs/.env-${GITHUB_REPOSITORY_NAME}
environment:
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ services:
# Password for root access
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- "3306"

- target: 3306
published: 3306
protocol: tcp
6 changes: 3 additions & 3 deletions docker-entry.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh

sleep 5
npm run build
npm start
cd /usr/src/app/server
node migrate.js
node index.js
5 changes: 1 addition & 4 deletions server/bin/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ const migrate = async () => {
multipleStatements: true, // Allow multiple SQL statements
});

// Drop the existing database if it exists
await database.query(`drop database if exists ${DB_NAME}`);

// Create a new database with the specified name
await database.query(`create database ${DB_NAME}`);
await database.query(`create database if not exists ${DB_NAME}`);

// Switch to the newly created database
await database.query(`use ${DB_NAME}`);
Expand Down
4 changes: 2 additions & 2 deletions server/database/schema.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
create table user (
create table if not exists user (
id int unsigned primary key auto_increment not null,
email varchar(255) not null unique,
password varchar(255) not null
);

create table item (
create table if not exists item (
id int unsigned primary key auto_increment not null,
title varchar(255) not null,
user_id int unsigned not null,
Expand Down

0 comments on commit ec65d65

Please sign in to comment.