From c1bcab20980371f555063de2263095b46c83ab7e Mon Sep 17 00:00:00 2001 From: Alexander Rogalsky Date: Sun, 6 Jun 2021 13:45:38 +0300 Subject: [PATCH] docs: updates on documents Added information on project structure --- .dockerignore | 3 +- .env | 5 +++ .github/workflows/preview.yml | 2 +- .github/workflows/qawolf.yml | 2 +- .github/workflows/release-semantic.yml | 2 +- .gitignore | 1 + .husky/post-commit | 4 ++ .npmrc | 3 ++ .nvmrc | 1 + .yarnrc | 3 ++ Dockerfile | 51 ++++++++++++++++---------- docker-compose.yml | 48 ++++++++++++++++++++++++ package.json | 6 ++- 13 files changed, 107 insertions(+), 24 deletions(-) create mode 100644 .env create mode 100644 .husky/post-commit create mode 100644 .npmrc create mode 100644 .nvmrc create mode 100644 .yarnrc create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore index b44ce08b..ecc14356 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,9 @@ -/.circleci /.dependabot /.github /.husky +/.idea /docs +/images /coverage /node_modules npm-debug.log diff --git a/.env b/.env new file mode 100644 index 00000000..c35a43a6 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +##################################################### +###### General settings +##################################################### +APP_HOSTNAME=styled-screenshots +APP_SERVER_PORT=3000 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 2fb50176..f9a6ffda 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/cache@v2.1.4 with: path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} restore-keys: | ${{ runner.os }}-node- diff --git a/.github/workflows/qawolf.yml b/.github/workflows/qawolf.yml index 6fdd1347..e8c24e12 100644 --- a/.github/workflows/qawolf.yml +++ b/.github/workflows/qawolf.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/cache@v1 with: path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} restore-keys: | ${{ runner.os }}-node- diff --git a/.github/workflows/release-semantic.yml b/.github/workflows/release-semantic.yml index 9459b0fc..5afaefb2 100644 --- a/.github/workflows/release-semantic.yml +++ b/.github/workflows/release-semantic.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/cache@v1 with: path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} restore-keys: | ${{ runner.os }}-node- diff --git a/.gitignore b/.gitignore index e71bf280..98dfb166 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ lerna-debug.log* # BlueJ files *.ctxt +*.iml # Cache files .npm diff --git a/.husky/post-commit b/.husky/post-commit new file mode 100644 index 00000000..a06768dc --- /dev/null +++ b/.husky/post-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run validate:commit diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..b73a7918 --- /dev/null +++ b/.npmrc @@ -0,0 +1,3 @@ +package-lock=false +save-exact=false +registry=http://registry.npmjs.org diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..2a0dc9a8 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +14.16.0 diff --git a/.yarnrc b/.yarnrc new file mode 100644 index 00000000..7bd7a52c --- /dev/null +++ b/.yarnrc @@ -0,0 +1,3 @@ +save-prefix "^" +--no-lockfile true +unsafe-disable-integrity-migration true diff --git a/Dockerfile b/Dockerfile index 9cc990fc..daeb7aa1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,43 +5,52 @@ ARG IMAGE_TAG=lts-alpine FROM $IMAGE_SOURCE:$IMAGE_TAG -MAINTAINER Alexander Rogalskiy <@AlexRogalskiy> +MAINTAINER Alexander Rogalskiy -## Setting arguments +## General arguments +ARG LC_ALL="en_US.UTF-8" ARG VERSION="0.0.0-dev" -ARG VCS_REF="$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")" ARG BUILD_DATE="$(git rev-parse --short HEAD)" -ARG HOME_DIR="/usr/src/app" +ARG VCS_REF="$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")" ## Vercel token ARG TOKEN -## Setting metadata -LABEL version=$VERSION -LABEL vcs-ref=$VCS_REF -LABEL build-date=$BUILD_DATE +## Working directories +ARG APP_DIR="/usr/src/app" +ARG DATA_DIR="/usr/src/data" + +## General metadata +LABEL "com.github.repository"="https://github.com/AlexRogalskiy/screenshots" +LABEL "com.github.homepage"="https://github.com/AlexRogalskiy/screenshots" +LABEL "com.github.maintainer"="Sensiblemetrics, Inc. (https://sensiblemetrics.io)" -LABEL name="Styled screenshots" -LABEL description="Automatically generate styled screenshots upon request (png, jpeg)" -LABEL repository="https://github.com/AlexRogalskiy/screenshots" -LABEL homepage="https://github.com/AlexRogalskiy" -LABEL maintainer="Nullables, Inc. (https://nullables.io)" +LABEL "com.github.version"="$VERSION" +LABEL "com.github.build-date"="$BUILD_DATE" +LABEL "com.github.vcs-ref"="$VCS_REF" + +LABEL "com.github.name"="styled-screenshots" +LABEL "com.github.description"="Automatically generate styled SVG screenshots upon request" ## Setting environment variables -ENV HOME $HOME_DIR -ENV LC_ALL en_US.UTF-8 +ENV APP_DIR $APP_DIR +ENV DATA_DIR $DATA_DIR +ENV LC_ALL $LC_ALL ENV LANG $LC_ALL ENV VERCEL_TOKEN $TOKEN +## Mounting volumes +VOLUME ["$APP_DIR"] + +## Creating work directory +WORKDIR $APP_DIR + ## Installing dependencies RUN apk add --no-cache git ## Installing vercel RUN npm i -g vercel -## Creating work directory -WORKDIR $HOME - ## Copying project sources COPY .vercel*/ ./.vercel COPY api/ ./api @@ -55,6 +64,10 @@ COPY package.json . ## Installing project dependencies RUN npm install + +## Run format checking & linting +RUN npm run all + RUN yes | vercel --confirm --token $VERCEL_TOKEN ## Setting volumes @@ -64,4 +77,4 @@ VOLUME /tmp EXPOSE 3000 ## Running package bundle -CMD ["npm", "run", "develop:docker"] +CMD ["npm", "run", "development:docker"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b74bd7ac --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +version: '3.9' + +services: + app: + container_name: styled-screenshots + hostname: '$APP_HOSTNAME' + build: + context: './' + dockerfile: Dockerfile + restart: always + volumes: + - type: volume + source: appvolume + target: /usr/src/app + volume: + nocopy: true + - type: bind + source: ./data + target: /usr/src/data + healthcheck: + test: ['CMD-SHELL', 'nc', '-vz', 'localhost', '3000'] + interval: 3s + retries: 15 + start_period: 30s + networks: + - default + ports: + - '${IP_ADDRESS:-127.0.0.1}:${APP_SERVER_PORT:-3000}:3000' + deploy: + mode: global + logging: + options: + max-size: '100m' + max-file: '10' + +networks: + default: + driver: bridge + driver_opts: + com.docker.network.driver.mtu: 1450 + +volumes: + appvolume: + driver: local + driver_opts: + o: bind + type: none + device: ./ diff --git a/package.json b/package.json index e1769e0f..43ce5eca 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "lint": "eslint --cache --fix --quiet --cache-location ./node_modules/.cache/ --format codeframe --ext js,ts .", "lint:clean": "del-cli .eslintcache", "lint:json": "jsonlint ./package.json --quiet", + "validate:commit": "validate-commit-msg", "sample": "cd samples && tsc && node ./dist/screenshot.js", "pretty": "pretty-quick --staged --pattern '!test/tests/lint/**'", "license": "license-checker --json > licenses.json", @@ -38,6 +39,7 @@ "test:watch": "env-cmd --silent -e test jest --watch", "test:license": "license-checker --production --summary --unknown --onlyAllow=\"Apache-2.0;BSD;ISC;MIT;GPL-3.0;CC-BY-3.0;CC0-1.0;Unlicense;\"", "lint:all": "npm run lint:clean && npm run lint && npm run lint:md && npm run lint:json", + "build-image": "docker build -f Dockerfile --tag styled-screenshots .", "format:all": "npm run format && npm run format:md", "check:all": "npm run format:check", "test:all": "npm run test && npm run test:license", @@ -103,7 +105,8 @@ "ts-jest": "^26.4.4", "ts-node": ">=9.0.0", "typedoc": "^0.20.28", - "typescript": "^4.1.3" + "typescript": "^4.1.3", + "validate-commit-msg": "^2.14.0" }, "repository": { "type": "git", @@ -157,6 +160,7 @@ "husky": { "hooks": { "pre-commit": "npm test:all", + "post-commit": "npm validate:commit", "pre-push": "npm run check:all" } },