Fix backend production deploy and database connection

- Fixed database URL locally and in production
- Set separate DB user just to be safe
- Migrate DB schema on each launch
- Use node user during dev but use root during deploy
- Fix output of the dev container (tsc-watch --noClear)
This commit is contained in:
Norbi Peti 2021-11-15 22:47:41 +01:00
parent c62925daf7
commit aa6f3f51de
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
10 changed files with 20 additions and 6 deletions

2
.gitignore vendored
View file

@ -46,3 +46,5 @@ testem.log
# System Files
.DS_Store
Thumbs.db
.firebase/

View file

@ -23,6 +23,8 @@ RUN apt-get update
RUN apt-get install -y docker-ce docker-ce-cli containerd.io
# Install Heroku CLI
RUN curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
# Install wait-for-it
RUN apt-get install -y wait-for-it
ENTRYPOINT [ "/docker.sh" ]
CMD [ "run" ]

View file

@ -24,5 +24,4 @@ RUN npm run build
# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0
EXPOSE ${PORT}
CMD [ "node", "." ]

View file

@ -19,4 +19,5 @@ echo "Installing packages"
npm install
echo "Running application"
npm run rebuild
wait-for-it database:3306 -t 0
npm run start:watch

View file

@ -33,7 +33,7 @@
"openapi-spec": "node ./dist/openapi-spec",
"prestart": "npm run rebuild",
"start": "node -r source-map-support/register .",
"start:watch": "tsc-watch --target es2017 --outDir ./dist --onSuccess \"node .\"",
"start:watch": "tsc-watch --target es2017 --outDir ./dist --onSuccess \"node .\" --noClear",
"clean": "lb-clean dist *.tsbuildinfo .eslintcache",
"rebuild": "npm run clean && npm run build"
},

View file

@ -4,7 +4,7 @@ import {juggler} from '@loopback/repository';
const config = {
name: 'database',
connector: 'mysql',
url: process.env.DATABASE_URL,
url: process.env.DATABASE_URL ?? process.env.CLEARDB_DATABASE_URL,
host: '',
port: 0,
user: '',

View file

@ -5,6 +5,7 @@ export * from './application';
export async function main(options: ApplicationConfig = {}) {
const app = new SzakdolgozatBackendApplication(options);
await app.boot();
await app.migrateSchema({existingSchema: 'alter'});
await app.start();
const url = app.restServer.url;

View file

@ -2,4 +2,4 @@
cd backend || exit
docker-compose build backend
docker-compose run -e COMMAND=deploy -v /var/run/docker.sock:/var/run/docker.sock backend
USERNAME="0" docker-compose run -e COMMAND=deploy -v /var/run/docker.sock:/var/run/docker.sock backend

View file

@ -15,13 +15,17 @@ services:
- ./backend:/home/node/app
environment:
- COMMAND=run
- DATABASE_URL=${CLEARDB_DATABASE_URL}
- DATABASE_URL=mysql://szakdolgozat:DevelopmentPassword@database/szakdolgozat
user: ${USERNAME:-node}
database:
image: mysql:5.6
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=DevelopmentPassword
- MYSQL_ROOT_PASSWORD=VerySecretPassword
- MYSQL_DATABASE=szakdolgozat
- MYSQL_USER=szakdolgozat
- MYSQL_PASSWORD=DevelopmentPassword
networks:
default:

5
frontend/.dockerignore Normal file
View file

@ -0,0 +1,5 @@
node_modules
npm-debug.log
/dist
# Cache used by TypeScript's incremental build
*.tsbuildinfo