diff --git a/.devcontainer/.env b/.devcontainer/.env new file mode 100644 index 00000000..ead5b338 --- /dev/null +++ b/.devcontainer/.env @@ -0,0 +1,5 @@ +POSTGRES_USER=postgres +POSTGRES_PASSWORD=trustify +POSTGRES_DB=trustify +POSTGRES_HOSTNAME=localhost +POSTGRES_PORT=5432 diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..c286a427 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1 @@ +FROM mcr.microsoft.com/devcontainers/base:ubuntu \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..677f4edc --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,28 @@ +{ + "name": "trustify", + "dockerComposeFile": "docker-compose.yml", + "service": "backend", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/rust:1": {} + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 8080, + 8090 + ], + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "bash .devcontainer/postCreateCommand.sh", + // Configure tool-specific properties. + "customizations": { + "vscode": { + }, + "jetbrains": { + "backend": "RustRover" + } + }, + // 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..09844c6a --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,37 @@ +networks: + trustification: + +volumes: + postgres-data: + +services: + backend: + build: + context: . + dockerfile: Dockerfile + environment: + TRUSTD_DB_HOST: db + HTTP_SERVER_BIND_ADDR: "::" # Required to disable IPv6 + volumes: + - ../..:/workspaces:cached + command: sleep infinity + networks: + - trustification + depends_on: + db: + condition: service_healthy + + db: + image: postgres:16 + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + env_file: + - .env + networks: + - trustification + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U $POSTGRES_USER -d $POSTGRES_DB" ] + interval: 10s + timeout: 5s + retries: 5 diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100755 index 00000000..e6fbb51c --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,10 @@ +apt-get update + +# Install OS Dependencies +apt-get -y install pkg-config + +## Git autocomplete +echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc + +## Initialize DB +cargo run --bin trustd db migrate \ No newline at end of file