Skip to content

Commit

Permalink
Optimized dockerfile, adopted express-openapi-validator, prisma and p…
Browse files Browse the repository at this point in the history
…ino-logger
  • Loading branch information
ymuichiro committed Dec 2, 2023
1 parent 8cb4b28 commit 1c5851e
Show file tree
Hide file tree
Showing 92 changed files with 10,706 additions and 2,721 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.env
.env.local
Dockerfile
README.MD
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
COOKIE_NAME=sample
COOKIE_SECRET=$ openssl rand -base64 128 | tr -d '\n'
COOKIE_DOMAIN=localhost:3000

DATABASE_URL=postgres://postgres:mysecretpassword@localhost:5432/mydatabase

11 changes: 0 additions & 11 deletions .env.sample

This file was deleted.

24 changes: 18 additions & 6 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
root: true
env:
browser: true
es2021: true
extends:
- google
- plugin:prettier/recommended
parser: '@typescript-eslint/parser'
- eslint:recommended
- plugin:@typescript-eslint/recommended
parser: "@typescript-eslint/parser"
parserOptions:
ecmaVersion: latest
sourceType: module
plugins:
- '@typescript-eslint'
rules: { 'new-cap': 'off', 'valid-jsdoc': 'off', 'require-jsdoc': 'off' }
- "@typescript-eslint"
rules:
indent:
- error
- 2
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
"@typescript-eslint/no-explicit-any": off
36 changes: 18 additions & 18 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
name: Publish Docker image
on: [workflow_dispatch]
name: Docker publish to ghcr.io

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:

jobs:
main:
name: Push Docker image to Github Container Registry
build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login
run: echo $CR_PAT | docker login ghcr.io -u ${OWNER,,} --password-stdin
env:
CR_PAT: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
- name: Push to GitHub Container Registry
uses: docker/build-push-action@v3
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
- uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
push: true
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/${{ github.repository }}:latest
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15
v20
4 changes: 3 additions & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
singleQuote: true
semi: true
printWidth: 120
trailingComma: es5
tabWidth: 2
quoteProps: consistent
trailingComma: none
endOfLine: lf
8 changes: 0 additions & 8 deletions .vscode/extensions.json

This file was deleted.

37 changes: 31 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
FROM node:16.15
# ----- stage 0 -----
FROM node:20-alpine

COPY . /app
WORKDIR /app/
COPY . .

RUN yarn install
RUN yarn run build
ENV NODE_ENV=production

EXPOSE 3000 3000
RUN \
npm ci --omit=dev && \
npx prisma generate

CMD [ "npm" , "run" , "run" ]
# ----- stage 1 -----
FROM node:20-alpine

COPY --from=0 /app/node_modules /app/node_modules
COPY --from=0 /app/src /app/src
COPY --from=0 /app/package.json /app/package.json
COPY --from=0 /app/tsconfig.json /app/tsconfig.json
COPY --from=0 /app/package-lock.json /app/package-lock.json
COPY --from=0 /app/prisma /app/prisma
COPY --from=0 /app/entrypoint.sh /app/entrypoint.sh
COPY --from=0 /app/schema/v1.yaml /app/schema/v1.yaml

WORKDIR /app/

ENV NODE_ENV=production

RUN addgroup -S app && adduser -S app -G app
USER app

EXPOSE 3000

LABEL "image_type"="boilerplate"

CMD [ "sh", "entrypoint.sh" ]
38 changes: 38 additions & 0 deletions bin/client/.github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# NOTE: This file is auto generated by OpenAPI Generator.
# URL: https://openapi-generator.tech
#
# ref: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: openapi_client Python package

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
66 changes: 66 additions & 0 deletions bin/client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.venv/
.python-version
.pytest_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
31 changes: 31 additions & 0 deletions bin/client/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# NOTE: This file is auto generated by OpenAPI Generator.
# URL: https://openapi-generator.tech
#
# ref: https://docs.gitlab.com/ee/ci/README.html
# ref: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml

stages:
- test

.pytest:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=openapi_client

pytest-3.7:
extends: .pytest
image: python:3.7-alpine
pytest-3.8:
extends: .pytest
image: python:3.8-alpine
pytest-3.9:
extends: .pytest
image: python:3.9-alpine
pytest-3.10:
extends: .pytest
image: python:3.10-alpine
pytest-3.11:
extends: .pytest
image: python:3.11-alpine
23 changes: 23 additions & 0 deletions bin/client/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
32 changes: 32 additions & 0 deletions bin/client/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.github/workflows/python.yml
.gitignore
.gitlab-ci.yml
.travis.yml
README.md
docs/Id.md
docs/User.md
docs/UserApi.md
docs/UsersGet200Response.md
docs/UsersPost200Response.md
git_push.sh
openapi_client/__init__.py
openapi_client/api/__init__.py
openapi_client/api/user_api.py
openapi_client/api_client.py
openapi_client/api_response.py
openapi_client/configuration.py
openapi_client/exceptions.py
openapi_client/models/__init__.py
openapi_client/models/id.py
openapi_client/models/user.py
openapi_client/models/users_get200_response.py
openapi_client/models/users_post200_response.py
openapi_client/py.typed
openapi_client/rest.py
pyproject.toml
requirements.txt
setup.cfg
setup.py
test-requirements.txt
test/__init__.py
tox.ini
1 change: 1 addition & 0 deletions bin/client/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.1.0
17 changes: 17 additions & 0 deletions bin/client/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
# uncomment the following if needed
#- "3.11-dev" # 3.11 development branch
#- "nightly" # nightly build
# command to install dependencies
install:
- "pip install -r requirements.txt"
- "pip install -r test-requirements.txt"
# command to run tests
script: pytest --cov=openapi_client
Loading

0 comments on commit 1c5851e

Please sign in to comment.