From acdcb5a78c5ead05984321a6f3f1d0288fc8eeac Mon Sep 17 00:00:00 2001 From: michal filo Date: Sat, 8 Jan 2022 14:44:41 +0100 Subject: [PATCH] docker --- .docker/node/start.sh | 3 +++ .github/workflows/main.yml | 10 ++-------- .gitignore | 3 ++- Dockerfile | 4 +++- Dockerfile.dev | 10 ---------- docker-compose.yml | 16 ++++++++++------ src/{config.example.ts => config.ts} | 3 +++ 7 files changed, 23 insertions(+), 26 deletions(-) create mode 100644 .docker/node/start.sh delete mode 100644 Dockerfile.dev rename src/{config.example.ts => config.ts} (91%) diff --git a/.docker/node/start.sh b/.docker/node/start.sh new file mode 100644 index 0000000..585e8cc --- /dev/null +++ b/.docker/node/start.sh @@ -0,0 +1,3 @@ +#!/bin/sh +yarn install --frozen-lockfile +yarn start diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 95e57af..a3cfc6d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,7 +40,6 @@ jobs: MYSQL_DATABASE: test MYSQL_ROOT_PASSWORD: password options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 - steps: - uses: actions/checkout@v1 - name: Install dependencies @@ -52,10 +51,6 @@ jobs: while ! mysqladmin ping -h"127.0.0.1" -P"$PORT" --silent; do sleep 1 done - - name: Rename config - env: - PORT: ${{ job.services.mariadb.ports[3306] }} - run: sed "s/3306/$PORT/g" src/config.example.ts > src/config.ts - name: Build projects, run migrations and seeds run: | yarn run build @@ -74,8 +69,7 @@ jobs: if: github.event_name == 'release' steps: - uses: actions/checkout@v2 - - name: Rename config - run: mv src/config.example.ts src/config.ts + - name: Build run: docker build -t $ORGANIZATION/$PROJECT_NAME . - name: Install doctl @@ -111,4 +105,4 @@ jobs: run: | VERSION=${GITHUB_REF#"refs/tags/"} - kubectl set image deployment/$PROJECT_NAME-deployment $PROJECT_NAME-application=registry.digitalocean.com/$ORGANIZATION/$PROJECT_NAME:$VERSION \ No newline at end of file + kubectl set image deployment/$PROJECT_NAME-deployment $PROJECT_NAME-application=registry.digitalocean.com/$ORGANIZATION/$PROJECT_NAME:$VERSION diff --git a/.gitignore b/.gitignore index 1310662..eb98ad5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ dist/ -src/config.ts coverage/ +.env.local +.idea diff --git a/Dockerfile b/Dockerfile index 030aff8..291f7c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ FROM node:16-alpine AS build -USER node RUN mkdir /home/node/express-graphql-example/ && chown -R node:node /home/node/express-graphql-example + +USER node + WORKDIR /home/node/express-graphql-example COPY --chown=node:node . . diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 99bd63a..0000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,10 +0,0 @@ -FROM node:16-alpine - -WORKDIR /application -COPY . . - -RUN yarn install --frozen-lockfile - -EXPOSE 3010 - -CMD [ "yarn", "start" ] diff --git a/docker-compose.yml b/docker-compose.yml index ae49dca..04fdb1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,9 @@ services: mysqldb: image: mysql restart: unless-stopped - env_file: ./.env + env_file: + - ./.env + - ./.env.local environment: - MYSQL_DATABASE=${DATABASE_NAME} - MYSQL_USER=${DATABASE_USER} @@ -14,13 +16,15 @@ services: - 'mysql_data:/mysql/data' application: - build: - context: . - dockerfile: Dockerfile.dev + image: node:16-alpine + working_dir: /application + command: sh /application/.docker/node/start.sh depends_on: - mysqldb restart: unless-stopped - env_file: ./.env + env_file: + - ./.env + - ./.env.local ports: - ${PORT}:${PORT} environment: @@ -32,7 +36,7 @@ services: links: - mysqldb volumes: - - "./src:/application/src" + - ".:/application" volumes: diff --git a/src/config.example.ts b/src/config.ts similarity index 91% rename from src/config.example.ts rename to src/config.ts index 61ad72d..c03b455 100644 --- a/src/config.example.ts +++ b/src/config.ts @@ -1,3 +1,6 @@ +/** + * Please set those values via .env file + */ export default { port: process.env.PORT || 3010, database: {