Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ugh #389

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

ugh #389

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/*
30 changes: 30 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
62 changes: 62 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=hid-local
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
coverage
docker-compose.yml
**/.DS_Store
keys
db
Expand Down
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"]
}
]
}