Skip to content

Commit

Permalink
Merge pull request #1 from gruz0/feature/init-project
Browse files Browse the repository at this point in the history
Initialize project
  • Loading branch information
gruz0 authored Sep 21, 2024
2 parents c67f9c0 + 1510c7b commit 03055ec
Show file tree
Hide file tree
Showing 25 changed files with 1,518 additions and 80 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
out
coverage
.git
.github
.env*
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -----------------------------------------------------------------------------
# General settings
# -----------------------------------------------------------------------------

export COMPOSE_PROJECT_NAME=checkmvp

export NEXT_PUBLIC_SITE_URL="http://localhost:3000"
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.next
node_modules
yarn.lock
package-lock.json
public
92 changes: 91 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,93 @@
{
"extends": ["next/core-web-vitals", "next/typescript"]
"root": true,
"parser": "@typescript-eslint/parser",
"extends": [
"next/core-web-vitals",
"plugin:prettier/recommended",
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:import/recommended",
"plugin:tailwindcss/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jsx-a11y/recommended",
"plugin:security/recommended-legacy",
"prettier",
"next"
],
"plugins": [
"react",
"import",
"filenames",
"autofix",
"unused-imports",
"@typescript-eslint",
"jsx-a11y",
"prettier",
"security"
],
"env": {
"jest": true
},
"rules": {
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
],
"arrow-body-style": ["error", "as-needed"],
"react/self-closing-comp": [
"error",
{
"component": true,
"html": true
}
],
"autofix/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"ignoreRestSiblings": true,
"destructuredArrayIgnorePattern": "^_"
}
],
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"parent",
"sibling",
"index",
"object",
"type"
],
"pathGroups": [
{
"pattern": "@/**/**",
"group": "parent",
"position": "before"
}
],
"alphabetize": { "order": "asc" }
}
],
"sort-imports": [
"error",
{
"ignoreDeclarationSort": true
}
]
}
}
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: 'docker'
directory: '/'
schedule:
interval: 'weekly'

- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'weekly'
20 changes: 20 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Docker Image CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: hadolint/[email protected]
with:
dockerfile: Dockerfile

- name: Prepare .env
run: cp .env.example .env.production

- name: Build the Docker image
run: make prod-docker-build
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 22.6.0
cache: npm

- name: Prepare .env
run: cp .env.example .env

- run: npm ci
- run: make lint
29 changes: 29 additions & 0 deletions .github/workflows/spell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# NOTE: https://github.com/rails/rails/blob/main/.github/workflows/lint.yml

name: Spell

on: [push, pull_request]

jobs:
codespell:
name: Check spelling all files with codespell
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.10']
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install codespell==2.1.0
- name: Check spelling with codespell
run: codespell --ignore-words=codespell.txt --skip "./node_modules,./package-lock.json" || exit 1
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.env*
!.env.example
!.env.test

# vercel
.vercel
Expand Down
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.next
node_modules
yarn.lock
package-lock.json
public
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"plugins": [],
"overrides": []
}
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Install dependencies only when needed
FROM node:22.6.0-alpine AS base

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
# hadolint ignore=DL3018
RUN apk add --update --no-cache libc6-compat
WORKDIR /app

COPY package.json package-lock.json ./

RUN npm ci

# Rebuild the source code only when needed
FROM node:22.6.0-alpine AS builder
WORKDIR /app

COPY --from=base /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

RUN npm run build

FROM node:22.6.0-alpine AS prod_builder
WORKDIR /app

ENV NODE_ENV production

COPY --from=base /app/node_modules ./node_modules
COPY . .

RUN npm install && \
cp -R node_modules prod_node_modules

# Production image, copy all the files and run next
FROM node:22.6.0-alpine AS runner
RUN apk add --update --no-cache curl=8.9.1-r2

WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

ARG UID=1001
ENV USER="app"

RUN adduser -D $USER -u $UID

# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder --chown=$USER:$USER /app/next.config.mjs ./
COPY --from=builder --chown=$USER:$USER /app/public ./public
COPY --from=builder --chown=$USER:$USER /app/package.json ./package.json
COPY --from=prod_builder --chown=$USER:$USER /app/prod_node_modules ./node_modules

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=$USER:$USER /app/.next/standalone ./
COPY --from=builder --chown=$USER:$USER /app/.next/static ./.next/static

USER $USER

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.DEFAULT_GOAL := help

NPM := npm
NPM_RUN := ${NPM} run
NPX := npx

DOCKER_COMPOSE := docker compose

help: # Show this help
@egrep -h '\s#\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

#
# Development environment
#

setup: # Install dependencies
@${NPM} install
@${NPM_RUN} prepare

prepare-dev-env:
@cp .env.development .env

analyze: prepare-dev-env # Analyze bundles
@${NPM_RUN} analyze

build: prepare-dev-env # Build project
@${NPM_RUN} build

dev: prepare-dev-env # Run dev server
@${NPM_RUN} dev

lint: # Run linters
@${NPM_RUN} lint

fix: # Run automatically fixes
@${NPM_RUN} next-lint-fix
@${NPX} prettier -w .

#
# Production environment
#

prepare-prod-env:
@cp .env.production .env

prod-docker-build: prepare-prod-env # Build Docker image
@${DOCKER_COMPOSE} -f docker-compose.production.yml build

prod-docker-start: prepare-prod-env # Run Docker container
@${DOCKER_COMPOSE} -f docker-compose.production.yml up -d

prod-docker-stop: prepare-prod-env # Stop Docker container
@${DOCKER_COMPOSE} -f docker-compose.production.yml down

prod-docker-app-cli: prepare-prod-env # Attach to Docker container
@${DOCKER_COMPOSE} -f docker-compose.production.yml exec app sh

prod-docker-logs: prepare-prod-env # Show production related logs
@${DOCKER_COMPOSE} -f docker-compose.production.yml logs -f
Empty file added codespell.txt
Empty file.
10 changes: 10 additions & 0 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
env_file: .env
stdin_open: true
tty: true
ports:
- 127.0.0.1:3000:3000
Loading

0 comments on commit 03055ec

Please sign in to comment.