Skip to content

Commit

Permalink
feat(dockerfile): added docker file
Browse files Browse the repository at this point in the history
Added support for Dockerfile while extracting git commit sha and version number

fix #5
  • Loading branch information
Manny authored and Manny committed Jul 10, 2020
1 parent 5b44331 commit fc60862
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
node_modules/
build
dist
*.log
.env
yarn.lock
package-lock.json
.eslintcache
**/.DS_Store
coverage
prisma/migrations/*.lock
.huskyrc
.lintstagedrc
.nvmrc
.prettierignore
.prettierrc
*.md
jest.config.js
.eslintignore
.eslintrc.js
commitlint.config.js
postman
.github
8 changes: 5 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PORT=5000
NODE_ENV=development
VERSION=1.0.0
VERSION=
ENABLE_EMAIL=false
CORS_ALLOW=http://localhost:3000;https://localhost:5000;http://app.local
CORS_ALLOW=http://localhost,http://localhost:3000;https://localhost:5000;http://app.local

JWT_SECRET=jwt_secret_key
JWT_ISSUER=api.localhost
Expand All @@ -26,4 +26,6 @@ EMAIL_FROM=noreply
EMAIL_SUBJECT_RESET="Reset Your Password"
EMAIL_SUBJECT_CONFIRM="Confirm Account"
EMAIL_URL_RESET_PASSWORD=http://localhost:3000/auth/reset
EMAIL_URL_CONFIRM_ACCOUNT=http://localhost:3000/auth/confirm
EMAIL_URL_CONFIRM_ACCOUNT=http://localhost:3000/auth/confirm

COMMIT=
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:alpine

COPY $PWD /home/node

WORKDIR /home/node

RUN yarn install --production=true; \
yarn build; \
apk add git; \
cp .env.example .env; \
sed -i "/COMMIT=/c\COMMIT=$(git log -1 --format="%H")" .env; \
sed -i "/VERSION=/c\VERSION=$(node -p 'require(`./package.json`).version')" .env; \
apk del git;

EXPOSE 80

CMD ["/bin/sh", "-c", "yarn start"]
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dotenv.config();

const NODE_ENV: string = process.env.NODE_ENV || 'development';
const VERSION: string = process.env.VERSION || 'unknown';
const COMMIT: string = process.env.COMMIT || 'unknown';

// Init
// ========================================================
Expand Down Expand Up @@ -46,7 +47,7 @@ app.use(csrfMiddleware);
// Endpoints / Routess
// ========================================================
app.get('/', (_req, res) =>
res.send({ version: VERSION, environment: NODE_ENV }),
res.send({ version: VERSION, environment: NODE_ENV, commit: COMMIT }),
);

app.use('/api', routes);
Expand Down
3 changes: 2 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import * as dotenv from 'dotenv';
// ========================================================
dotenv.config();

const PORT: number = parseInt(process.env.PORT as string, 10);
const NODE_ENV: string = process.env.NODE_ENV || 'development';
const PORT: number =
NODE_ENV === 'production' ? 80 : parseInt(process.env.PORT as string, 10);
const VERSION: string = process.env.VERSION || 'unknown';

// Server
Expand Down

0 comments on commit fc60862

Please sign in to comment.