Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker + API design scripts #20

Merged
merged 5 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions scaffold/service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM node:12.16.3-alpine as ts-build
# Arguments
ARG NODE_ENV
ARG NPM_TOKEN
ARG SERVICE_PORT
ENV NODE_ENV=$NODE_ENV \
SERVICE_PORT=$SERVICE_PORT \
APP_DIR="/usr/src/{{{scaffold_docker_path}}}" \
Expand Down Expand Up @@ -48,7 +49,8 @@ FROM node:12.16.3-alpine as build
ENV APP_DIR=/usr/src/{{{scaffold_docker_path}}} \
YARN_CACHE="/tmp/ycache" \
NODE_ENV=$NODE_ENV \
NPM_TOKEN=$NPM_TOKEN
NPM_TOKEN=$NPM_TOKEN \
SERVICE_PORT=$SERVICE_PORT

RUN mkdir -p $APP_DIR
RUN mkdir -p $YARN_CACHE
Expand All @@ -73,9 +75,10 @@ FROM node:12.16.2-alpine

# Arguments
ARG NODE_ENV
ARG SERVICE_PORT

# Configuration
ENV SERVICE_PORT={{{scaffold_service_port}}} \
ENV SERVICE_PORT=$SERVICE_PORT \
SERVICE_USER={{{scaffold_server_name}}} \
SERVICE_USER_ID=1001 \
SERVICE_GROUP={{{scaffold_server_name}}} \
Expand Down
6 changes: 5 additions & 1 deletion scaffold/service/package.json.replace
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
"clean": "rm -rf lib/*",
"clean:build": "yarn clean && yarn build",
"dev": "nodemon",
"doc": "scripts/doc.sh",
"doc": "scripts/doc.sh {{{scaffold_project_name}}}",
"doc:lint": "scripts/doc_lint.sh {{{scaffold_project_name}}}",
"dump": "ts-node -- src/persistence/mongoose/backup.ts",
"lint": "eslint 'src/**'",
"postinstall": "[ \"$NODE_ENV\" == production ] && exit 0; yarn clean:build",
"prepublish": "yarn clean:build",
"prettify:lib": "prettier --write 'lib/**'",
"build:docker": "scripts/docker-build.sh",
"docker:permission": "chmod -R +x scripts/*.sh",
"run:docker": "yarn docker:permission && yarn build:docker && scripts/docker-run.sh",
"pretest": "yarn lint",
"seed": "ts-node -- src/persistence/mongoose/seed.ts",
"start": "node lib/index.js",
Expand Down
7 changes: 7 additions & 0 deletions scaffold/service/scripts/doc-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

API="$1";

[ $# -ne 1 ] && { echo "Usage: pass API service name as argument"; exit 1;}

npx spectral lint "doc/${API}.yaml";
9 changes: 9 additions & 0 deletions scaffold/service/scripts/doc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

API="$1";

[ $# -ne 1 ] && { echo "Usage: pass API service name as argument"; exit 1;}

npx redoc-cli bundle "doc/${API}.yaml";
rm -f "doc/${API}.html" && mv redoc-static.html "doc/${API}.html";
exit 0;
10 changes: 10 additions & 0 deletions scaffold/service/scripts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

NODE_ENV=$1
NPM_TOKEN=$2
SERVICE_PORT={{{scaffold_service_port}}};
APP_NAME={{{scaffold_docker_path}}};


docker build -t "$APP_NAME" --build-arg NODE_ENV=$NODE_ENV --build-arg SERVICE_PORT=$SERVICE_PORT --build-arg NPM_TOKEN=$NPM_TOKEN .;
exit 0;
4 changes: 4 additions & 0 deletions scaffold/service/scripts/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

docker run -p 4021:4021 {{{scaffold_docker_path}}}:latest;
exit 0;