diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100755 index 00000000..8943f4ed --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,12 @@ +FROM public.ecr.aws/unocha/nodejs:14-alpine + +WORKDIR /srv/www + +RUN apk add \ + cracklib \ + cracklib-dev \ + docker \ + git \ + gpg \ + gpg-agent && \ + rm -rf /var/cache/apk/* diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100755 index 00000000..274e27ca --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,30 @@ +# VSCode, Dev Containers based development + +## Host setup + +1. Install VSCode +1. Install the "Git Project Manager", "Docker" and the "Dev Containers" VSCode extensions +1. Clone hid-api repository from the VSCode Source Control "Clone Repository" +1. Checkout this branch (until this is merged to dev) +1. When the "Open in container" pop up appears, click it. + + +## Database restore + +1. Download the latest mongo archive (e.g. `20221216.bson.tar`) somewhere locally (e.g. `~/src/20221216.bson.tar`) +1. Make sure you have activated at least once the VSCode Dev Containers environment for hid; this means you will have a `hi d-local-db-1` container: + `docker ps -a | grep "hid-local-db-1"` +1. make sure the mongo container is running (if you have activated the VSCode Dev Containers environment, it probably is running) + `docker start hid-local-db-1` +1. In a local terminal (not in VSCode), copy the mongo archive into the db container: + `docker cp ~/src/20221216.bson.tar hid-local-db-1:/snapshots/production.bson.tar` +1. Uncompress the mongo archive: + `docker exec hid-local-db-1 sh -c "cd /snapshots && tar xf production.bson.tar"` +1. Restore the mongo archive in your local mongo container: + `docker exec hid-local-db-1 sh -c "cd /snapshots && mongorestore --gzip --drop -d local /snapshots/production` + +## Day by day develoment + +1. Open VSCode +1. Open your hid-api repository +1. Click the "Reopen in container" button when it pops up diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..94ef3a90 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,64 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose +// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml. +{ + "name": "Existing Docker Compose (Extend)", + + // Update the 'dockerComposeFile' list if you have more compose files or use different names. + // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. + "dockerComposeFile": [ + "docker-compose.yml" + ], + + // The 'service' property is the name of the service for the container that VS Code should + // use. Update this value and .devcontainer/docker-compose.yml to the real service name. + "service": "api", + + // The optional 'workspaceFolder' property is the path VS Code should open by default when + // connected. This is typically a file mount in .devcontainer/docker-compose.yml + // "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}" + "workspaceFolder": "/srv/www", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line if you want start specific services in your Docker Compose config. + // "runServices": [], + + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + + // Uncomment the next line to run commands after the container is created - for example installing curl. + // "postCreateCommand": "apt-get update && apt-get install -y curl", + "postCreateCommand": "apk add --virtual .build-deps python3 python3-dev build-base && npm install && npm run docs && apk del .build-deps", + + // Configure tool-specific properties. + // "customizations": {}, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/sh" + } + } + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "eamodio.gitlens", + "GitHub.vscode-pull-request-github", + "felipecaputo.git-project-manager" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..31b3105e --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,62 @@ +version: '2.2' +services: + # Update this to the name of the service you want to work with in your docker-compose.yml file + api: + # If you want add a non-root user to your Dockerfile, you can use the "remoteUser" + # property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks, + # debugging) to execute as the user. Uncomment the next line if you want the entire + # container to run as this user instead. Note that, on Linux, you may need to + # ensure the UID and GID of the container user you create matches your local user. + # See https://aka.ms/vscode-remote/containers/non-root for details. + # + # Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + # user: root + + # image: public.ecr.aws/unocha/hid-api:dev + build: + context: . + dockerfile: Dockerfile + + volumes: + - ../:/srv/www:cached + # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details. + - /var/run/docker.sock:/var/run/docker.sock + + # Overrides default command so things don't shut down after the process ends. + entrypoint: /bin/sh -c "while sleep 1000; do :; done" + + environment: + NODE_ENV: local + ROOT_URL: http://api.hid.vm:3000 + SMTP_HOST: mailhog + SMTP_PORT: 1025 + SMTP_USER: '' + SMTP_PASS: '' + APP_URL: http://app.hid.vm + COOKIE_PASSWORD: 6*a!_5;1:|7~+%5**WdS:^;X%PN||~:_:_R + WKHTMLTOPDF_HOST: pdf.contactsid.vm + WKHTMLTOPDF_PORT: 3000 + + db: + image: mongo:6-focal + volumes: + - mongo_db:/data/db + - snapshots:/snapshots + command: --bind_ip_all + + mailhog: + image: public.ecr.aws/unocha/mailhog:stable + ports: + - 0.0.0.0:8025:8025 + + redis: + image: public.ecr.aws/unocha/redis:5 + volumes: + - "redis_db:/var/lib/redis" + - "redis_log:/var/log/redis" + +volumes: + mongo_db: + redis_db: + redis_log: + snapshots: diff --git a/.env b/.env new file mode 100755 index 00000000..9c8f12a7 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=hid-local diff --git a/.gitignore b/.gitignore index b2391832..82f7ca3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ node_modules coverage -docker-compose.yml **/.DS_Store keys db diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100755 index 00000000..f9248f58 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Run", + "type": "node", + "request": "launch", + "cwd": "${workspaceFolder}", + "runtimeExecutable": "npm", + "runtimeArgs": ["run", "dev"] + } + ] +}