diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..801e184 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +coverage diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..52975ad --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,25 @@ +name: Deploy + +on: + push: + branches: [dev] + +jobs: + deploy-stage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: ${{secrets.HEROKU_APP_NAME}} + heroku_email: ${{secrets.HEROKU_ACCOUNT_EMAIL}} + usedocker: true + stack: "container" + healthcheck: | + "https://" + ${{secrets.HEROKU_STAGING_APP_NAME}} + ".herokuapp.com/health" + checkstring: "ok" + delay: 60 + rollbackonhealthcheckfailed: true diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..03f6869 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,25 @@ +name: Deploy + +on: + push: + branches: [master] + +jobs: + deploy-prod: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: ${{secrets.HEROKU_APP_NAME}} + heroku_email: ${{secrets.HEROKU_ACCOUNT_EMAIL}} + usedocker: true + stack: "container" + healthcheck: | + "https://" + ${{secrets.HEROKU_APP_NAME}} + ".herokuapp.com/health" + checkstring: "ok" + delay: 60 + rollbackonhealthcheckfailed: true diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..a836911 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +.github/ +docker-compose.yml +node_modules +dist +coverage diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3a2d0d6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# # pulling the suitable version of node +FROM node:14.16 as build + +# specifying the container app directory +WORKDIR /khushal/src/app + +# copy package.json and everything in the directory +COPY package.json ./ + +RUN npm install + +# first dot - the working directory +# second dot - the docker app directory +COPY . . + +# build the project +RUN npm run build + +# ----------------------------- + +# Production container + +FROM node:14.16 +WORKDIR /user/src/app +COPY package.json . +RUN npm install --only=production +COPY --from=build /khushal/src/app/dist ./dist +# COPY --from=build /khushal/src/app/.env ./ +CMD npm run start:prod diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..30fe509 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.8" +services: + api: + # image: khushalbhardwaj-0111/notary + build: + dockerfile: Dockerfile + context: ./ + environment: + NODE_ENV: production + ports: + - "8080:80" diff --git a/package.json b/package.json index 15547e9..b0e9b5b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "notary-api", "private": true, - "version": "1.0.0", + "version": "1.0.1", "description": "Notary API", "license": "MIT", "scripts": { @@ -13,6 +13,8 @@ "start:dev": "nest build --webpack --webpackPath webpack.config.js --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", + "up": "docker-compose up", + "down": "docker-compose down", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", @@ -77,6 +79,9 @@ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", - "testEnvironment": "node" + "testEnvironment": "node", + "engines": { + "node": "14.x" + } } } diff --git a/src/main.ts b/src/main.ts index dee8066..dea9a54 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,14 +8,14 @@ dotenv.config(); declare const module: any; (async function bootstrap() { - const app = await NestFactory.create(AppModule); - app.enableCors(); - app.use(helmet()); + const app = await NestFactory.create(AppModule); + app.enableCors(); + app.use(helmet()); - if (module.hot) { - module.hot.accept(); - module.hot.dispose(() => app.close()); - } + if (module.hot) { + module.hot.accept(); + module.hot.dispose(() => app.close()); + } - await app.listen(process.env.PORT || 8080); + await app.listen(process.env.PORT || 80); })();