Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
create the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidenori MATSUKI authored and Hidenori MATSUKI committed Feb 27, 2020
1 parent 39e413a commit 9cf6cf9
Show file tree
Hide file tree
Showing 61 changed files with 25,160 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.env
/.eslintrc.json
node_modules/
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["browser-preview.chromeExecutable"]
}
1 change: 1 addition & 0 deletions Dockerfile.d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootfs/
27 changes: 27 additions & 0 deletions Dockerfile.d/bff.development/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:12 as base

# Set in non-interactive mode.
ENV DEBIAN_FRONTEND=noninteractive

ARG GID=0
ARG UID=0
ENV GID=${GID:-0}
ENV UID=${UID:-0}

RUN echo 'apt::install-recommends "false";' > /etc/apt/apt.conf.d/no-install-recommends\
&& apt-get update\
&& apt-get install --assume-yes locales procps dialog\
&& echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen\
&& locale-gen\
&& apt-get install --assume-yes sudo dnsutils git tmux zsh jq\
&& apt-get install --assume-yes default-mysql-client redis-tools\
&& addgroup --gid ${GID} developer || true\
&& adduser --disabled-password --uid ${UID} --gecos '' --gid ${GID} developer || true\
# It will be duplicate UID or GID with "node" user when your UID==1000 or GID==100.
&& echo '%users ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/grant-all-without-password-to-users\
&& echo '%developer ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/grant-all-without-password-to-developer

# Reset DEBIAN_FRONTEND to default(`dialog`).
# If you no need `dialog`, you can set `DEBIAN_FRONTEND=readline`.
# see also: man 7 debconf
ENV DEBIAN_FRONTEND=
29 changes: 29 additions & 0 deletions Dockerfile.d/bff/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:12-alpine as base

# ================================
# Begin builder stage
FROM base as builder
COPY rootfs /
WORKDIR /workspace

# See https://github.com/kelektiv/node.bcrypt.js/issues/615#issuecomment-407300081
RUN apk add --no-cache --virtual deps python build-base\
&& npm install\
&& apk del deps\
&& npm run test\
&& npm run build
# End builder stage
# ================================

# ================================
# Begin production stage
FROM base as production
# See https://github.com/nodejs/docker-node/blob/8bcc1712f430dcf5f22fffd6aef3db82698c296c/docs/BestPractices.md#handling-kernel-signals
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
# COPY --from=builder /workspace/dist/main.js /app/
RUN mkdir -p /data/config/bff/ && echo '{}' > /data/config/bff/config.json
COPY --from=builder /workspace/dist/main.js /app/
CMD ["node", "/app/main.js"]
# End production stage
# ================================
23 changes: 23 additions & 0 deletions Dockerfile.d/frontend.development/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:12 as base

# Set in non-interactive mode.
ENV DEBIAN_FRONTEND=noninteractive

ARG GID=0
ARG UID=0
ENV GID=${GID:-0}
ENV UID=${UID:-0}

RUN echo 'apt::install-recommends "false";' > /etc/apt/apt.conf.d/no-install-recommends\
&& apt-get update\
&& apt-get install --assume-yes --no-install-recommends locales procps dialog\
&& echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen\
&& locale-gen\
&& apt-get install --assume-yes sudo dnsutils git tmux zsh jq\
&& addgroup --gid ${GID} developer || true\
&& adduser --disabled-password --uid ${UID} --gecos '' --gid ${GID} developer || true

# Reset DEBIAN_FRONTEND to default(`dialog`).
# If you no need `dialog`, you can set `DEBIAN_FRONTEND=readline`.
# see also: man 7 debconf
ENV DEBIAN_FRONTEND=
26 changes: 26 additions & 0 deletions Dockerfile.d/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:12-alpine as base

# ================================
# Begin builder stage
FROM base as builder
COPY rootfs /
WORKDIR /workspace
RUN npm install\
&& npm run test\
&& npm run build\
&& mkdir -p /app\
&& tar c .next/ node_modules/ package.json | tar x -C /app
# End builder stage
# ================================

# ================================
# Begin production stage
FROM base as production
# See https://github.com/nodejs/docker-node/blob/8bcc1712f430dcf5f22fffd6aef3db82698c296c/docs/BestPractices.md#handling-kernel-signals
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
WORKDIR /app
COPY --from=builder /app .
CMD ["npm", "run", "start"]
# End production stage
# ================================
26 changes: 26 additions & 0 deletions Dockerfile.d/image-publisher/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM google/cloud-sdk:280.0.0

# Set in non-interactive mode.
ENV DEBIAN_FRONTEND=noninteractive

ARG GID=0
ARG UID=0
ENV GID=${GID:-0}
ENV UID=${UID:-0}

ENV TERRAFORM_VERSION=0.12.9

RUN echo 'apt::install-recommends "false";' > /etc/apt/apt.conf.d/no-install-recommends\
&& apt-get update\
&& apt-get install --assume-yes locales procps dialog\
&& echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen\
&& locale-gen\
&& apt-get install --assume-yes sudo dnsutils git tmux zsh jq unzip\
&& addgroup --gid ${GID} developer || true\
&& adduser --disabled-password --uid ${UID} --gecos '' --gid ${GID} developer || true\
&& echo '%developer ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/grant-all-without-password-to-developer

# Reset DEBIAN_FRONTEND to default(`dialog`).
# If you no need `dialog`, you can set `DEBIAN_FRONTEND=readline`.
# see also: man 7 debconf
ENV DEBIAN_FRONTEND=
23 changes: 23 additions & 0 deletions Dockerfile.d/vscode/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:12 as base

# Set in non-interactive mode.
ENV DEBIAN_FRONTEND=noninteractive

ARG GID=0
ARG UID=0
ENV GID=${GID:-0}
ENV UID=${UID:-0}

RUN echo 'apt::install-recommends "false";' > /etc/apt/apt.conf.d/no-install-recommends\
&& apt-get update\
&& apt-get install --assume-yes --no-install-recommends locales procps dialog\
&& echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen\
&& locale-gen\
&& apt-get install --assume-yes --no-install-recommends jq\
&& addgroup --gid ${GID} developer || true\
&& adduser --disabled-password --uid ${UID} --gecos '' --gid ${GID} developer || true

# Reset DEBIAN_FRONTEND to default(`dialog`).
# If you no need `dialog`, you can set `DEBIAN_FRONTEND=readline`.
# see also: man 7 debconf
ENV DEBIAN_FRONTEND=
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
# 202002.dockerized-webapp-project
# 202002.dockerized-webapp-project

## Prepare

1. Download cargo-make

Linux:

```shellsession
export CARGO_MAKE_VERSION="0.26.1" \
&& curl -sL https://github.com/sagiegurari/cargo-make/releases/download/${CARGO_MAKE_VERSION}/cargo-make-v${CARGO_MAKE_VERSION}-x86_64-unknown-linux-musl.zip \
| busybox unzip -p - cargo-make-v${CARGO_MAKE_VERSION}-x86_64-unknown-linux-musl/cargo-make > bin/cargo-make && chmod a+x bin/cargo-make
```

macOS:

```shellsession
export CARGO_MAKE_VERSION="0.26.1" \
&& curl -sL https://github.com/sagiegurari/cargo-make/releases/download/${CARGO_MAKE_VERSION}/cargo-make-v${CARGO_MAKE_VERSION}-x86_64-apple-darwin.zip \
| bsdtar --strip-components 1 -C bin/ -xvf - cargo-make-v${CARGO_MAKE_VERSION}-x86_64-apple-darwin/cargo-make
```

2. Set up the project via cargo-make you downloaded.

```shellsession
bin/cargo-make make --makefile tasks/setup-project.toml
```

3. Place GCP service account key file.

Place the service account key file as `config/credentials/google-cloud-keyfile.json`

4. Up the Docker Compose once.

This step is needed to activate the GCP service account.

```shellsession
docker-compose up
```

## How to build & publish the Docker Images

Run `cargo-make` to build and push docker images.

```shellsession
bin/cargo-make make --makefile tasks/build-and-push-images.toml
```

## Appendix

You can check the GCP service account that activated as below.

```shellsession
gcloud iam service-accounts list
```

If you are a user of 1Password, you can get the GCP service account key file that below step.

```shellsession
eval $(op signin my)
op get document [email protected] > config/credentials/google-cloud-keyfile.json
```
28 changes: 28 additions & 0 deletions bff/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"env": {
"node": true,
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"sort-imports": "warn",
"prettier/prettier": [
"error",
{
"singleQuote": true,
"semi": false
}
]
}
}
5 changes: 5 additions & 0 deletions bff/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/dist/
/coverage/
/ormconfig.json
/*.dev.json
13 changes: 13 additions & 0 deletions bff/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest'
},
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json'
}
},
moduleDirectories: ['node_modules', 'src'],
verbose: true
}
Loading

0 comments on commit 9cf6cf9

Please sign in to comment.