From fff5306fa6a938e566c12798cac7bb8074b451cc Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Mon, 30 Jan 2023 00:41:27 +0100 Subject: [PATCH] chore: introduce .devcontainer --- .devcontainer/Dockerfile | 1 + .devcontainer/boot.sh | 48 ++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 47 +++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 31 +++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/boot.sh create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..8886e959 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1 @@ +FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-22.04 diff --git a/.devcontainer/boot.sh b/.devcontainer/boot.sh new file mode 100644 index 00000000..d2deaf1e --- /dev/null +++ b/.devcontainer/boot.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +CURRENT_DIR="$(pwd)" +BACKEND_PORT=3000 +WEB_PORT=3001 + +echo "Configuring backend environment variables..." +cd packages/backend +rm -rf .env +echo " +HOST=localhost +PROTOCOL=http +PORT=$BACKEND_PORT +WEB_APP_URL=https://$CODESPACE_NAME-$WEB_PORT.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN +APP_ENV=development +POSTGRES_DATABASE=automatisch +POSTGRES_PORT=5432 +POSTGRES_HOST=postgres +POSTGRES_USERNAME=automatisch_user +POSTGRES_PASSWORD=automatisch_password +ENCRYPTION_KEY=sample_encryption_key +WEBHOOK_SECRET_KEY=sample_webhook_secret_key +APP_SECRET_KEY=sample_app_secret_key +REDIS_HOST=redis +SERVE_WEB_APP_SEPARATELY=true" >> .env +cd $CURRENT_DIR + +echo "Configuring web environment variables..." +cd packages/web +rm -rf .env +echo " +PORT=$WEB_PORT +REACT_APP_GRAPHQL_URL=https://$CODESPACE_NAME-$BACKEND_PORT.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN/graphql +REACT_APP_BASE_URL=https://$CODESPACE_NAME-$WEB_PORT.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN +REACT_APP_NOTIFICATIONS_URL=https://notifications.automatisch.io +" >> .env +cd $CURRENT_DIR + +echo "Installing and linking dependencies..." +yarn +yarn lerna bootstrap + +echo "Migrating database..." +cd packages/backend +yarn db:migrate +yarn db:seed:user + +echo "Done!" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..3481bdbf --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,47 @@ +{ + "name": "Automatisch", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + "features": { + "ghcr.io/devcontainers/features/git:1": { + "version": "latest" + }, + "ghcr.io/devcontainers/features/node:1": { + "version": 16 + }, + "ghcr.io/devcontainers/features/common-utils:1": { + "username": "vscode", + "uid": 1000, + "gid": 1000, + "installZsh": true, + "installOhMyZsh": true, + "configureZshAsDefaultShell": true, + "upgradePackages": true + } + }, + + "portsAttributes": { + "3000": { + "label": "Backend", + "onAutoForward": "silent", + "protocol": "http" + }, + "3001": { + "label": "Frontend", + "onAutoForward": "silent", + "protocol": "http" + } + }, + + "forwardPorts": [3000, 3001], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": ["bash", ".devcontainer/boot.sh"] + + // Configure tool-specific properties. + // "customizations": {}, + + // 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..445d6fee --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.9' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + volumes: + - ..:/workspace:cached + command: sleep infinity + postgres: + image: 'postgres:14.5-alpine' + environment: + - POSTGRES_DB=automatisch + - POSTGRES_USER=automatisch_user + - POSTGRES_PASSWORD=automatisch_password + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'] + interval: 10s + timeout: 5s + retries: 5 + redis: + image: 'redis:7.0.4-alpine' + volumes: + - redis_data:/data + +volumes: + postgres_data: + redis_data: