-
Notifications
You must be signed in to change notification settings - Fork 0
feat/pre deployment setup #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c8f7d4c
chore: rename mapswipe-module to module
thenav56 a8a17d6
feat(stage): add terraform (tofu) with terragrunt
thenav56 563e624
lint(terraform): add pre-commit config
thenav56 3f6b13a
feat(postgres): setup postgres + pgbackrest docker
thenav56 9230514
feat(postgres): docker-compose setup with ofelia
thenav56 1eebf6b
feat(web-app): setup manager and community dashboard with Caddy
thenav56 f0dd378
lint: additional pre-commit hooks
thenav56 8f7d73e
lint: add pre-commit github workflow
thenav56 c8e64c8
feat(backend): setup web/worker and caddy
thenav56 527d07e
docs: deployment
thenav56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # vim: filetype=bash | ||
|
|
||
| COMPOSE_PROFILES=core | ||
| COMPOSE_PROJECT_NAME=mapswipe-deploy | ||
| MAPSWIPE_ENVIRONMENT=prod|stage | ||
|
|
||
| # Ofelia | ||
| OFELIA_PROJECT_NAME=mapswipe-prod | ||
| OFELIA_SLACK_WEBHOOK= | ||
|
|
||
| # Postgres | ||
| # NOTE: Password: Use openssl rand -base64 48 | tr -dc 'A-Za-z0-9_@#%^+=-' | head -c 24 | ||
| POSTGRES_USER= | ||
| POSTGRES_PASSWORD= | ||
|
|
||
| # Caddy | ||
| CADDY_EMAIL=mapswipe@example.org | ||
| CADDY_HOST_BACKEND=https://backend.example.org | ||
| CADDY_HOST_MANAGER_DASHBOARD=https://manager.example.org | ||
| CADDY_HOST_COMMUNITY_DASHBOARD=https://community.example.org | ||
|
|
||
| # PgBackRest | ||
| # https://pgbackrest.org/command.html | ||
| # https://pgbackrest.org/configuration.html#introduction | ||
| PGBACKREST_REPO1_GCS_BUCKET=demo-bucket | ||
| PGBACKREST_REPO1_PATH=/demo-repo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| name: Pre commit | ||
|
|
||
| on: | ||
| push: | ||
|
|
||
| jobs: | ||
| pre_commit_checks: | ||
| name: Pre-Commit checks | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@main | ||
| with: | ||
| submodules: true | ||
|
|
||
| - name: Generate fake ./terraform/live/secrets.auto.tfvars | ||
| run: | | ||
| echo "project_id_map = { stage = \"mapswipe\" }" > ./terraform/live/secrets.auto.tfvars | ||
|
|
||
| # TODO: Cache plugins? | ||
| - uses: terraform-linters/setup-tflint@v5 | ||
| name: Setup TFLint | ||
| with: | ||
| tflint_version: v0.52.0 | ||
|
|
||
| - name: Install Terragrunt and OpenTofu | ||
| uses: gruntwork-io/terragrunt-action@v3 | ||
| with: | ||
| # TODO: Use mise instead? https://github.com/gruntwork-io/terragrunt-action#tool-version-management | ||
| tg_version: 0.80.4 | ||
| tofu_version: v1.10.5 | ||
|
|
||
| - name: Initialize tofu without any backend | ||
| run: | | ||
| # Find all directories containing terragrunt.hcl | ||
| find . -type f -name "terragrunt.hcl" | while read hcl_file; do | ||
| dir=$(dirname "$hcl_file") | ||
| echo "Entering directory: $dir" | ||
| ( | ||
| cd "$dir" || exit | ||
| tofu init -backend=false | ||
| ) | ||
| done | ||
|
|
||
| - uses: pre-commit/action@main | ||
| env: | ||
| DISABLE_INIT: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .env* | ||
| !.env.sample | ||
| data/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| repos: | ||
| - repo: https://github.com/gitleaks/gitleaks | ||
| rev: v8.24.2 | ||
| hooks: | ||
| - id: gitleaks | ||
|
|
||
| - repo: https://github.com/crate-ci/typos | ||
| rev: v1.31.1 | ||
| hooks: | ||
| - id: typos | ||
| args: ["--exclude=CHANGELOG.md", "--force-exclude"] | ||
|
|
||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v6.0.0 | ||
| hooks: | ||
| - id: trailing-whitespace | ||
| - id: end-of-file-fixer | ||
| - id: check-yaml | ||
| - id: check-case-conflict | ||
| - id: detect-private-key | ||
| - id: check-merge-conflict | ||
| - id: trailing-whitespace | ||
| - id: end-of-file-fixer | ||
| - id: check-json | ||
| - id: check-toml | ||
| - id: check-xml | ||
| - id: check-yaml | ||
| args: [--unsafe] | ||
| - id: debug-statements | ||
| - id: detect-private-key | ||
|
|
||
| - repo: https://github.com/antonbabenko/pre-commit-terraform | ||
| rev: "v1.100.0" | ||
| hooks: | ||
| - id: terraform_fmt | ||
| - id: terraform_tflint | ||
| - id: terragrunt_fmt | ||
| - id: terragrunt_validate_inputs | ||
| files: (/terragrunt\.hcl)$ | ||
| - id: terragrunt_validate | ||
| files: (/terragrunt\.hcl)$ | ||
| args: | ||
| - --hook-config=--tf-path=tofu | ||
| # - id: terraform_trivy | ||
| # - id: infracost_breakdown |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| ## Setup | ||
|
|
||
| ### Cloning the Repository | ||
|
|
||
| Most submodules use SSH URLs. To avoid setting up SSH keys, run this command to use HTTPS instead: | ||
|
|
||
| ```bash | ||
| git config --global url."https://github.com/".insteadOf "git@github.com:" | ||
| ``` | ||
|
|
||
| Clone and pull all submodules | ||
| ```bash | ||
| git clone git@github.com:mapswipe/mapswipe-deploy.git | ||
| cd mapswipe-deploy | ||
| git submodule update --init --recursive | ||
| ``` | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| Make sure these environment files are in place: | ||
|
|
||
| - .env (based on `.env.sample`) | ||
| - env/backend.env | ||
| - env/community-dashboard.env | ||
| - env/manager-dashboard.env | ||
| - secrets/pgbackrest_gc_service_account_key.json | ||
|
|
||
| ```bash | ||
| cp .env.sample .env | ||
| touch env/backend.env | ||
| touch env/community-dashboard.env | ||
| touch env/manager-dashboard.env | ||
| touch secrets/pgbackrest_gc_service_account_key.json | ||
| ``` | ||
|
|
||
| ## Apply changes | ||
|
|
||
| The `task` tool is used to set up a pre-alias. | ||
| > https://taskfile.dev/ | ||
|
|
||
|
|
||
| ```bash | ||
| task --list-all | ||
|
|
||
| # Deploy all | ||
| task deploy | ||
|
|
||
| # Deploy web apps | ||
| task web-builds | ||
|
|
||
| # Deploy backend resources | ||
| task backend-deploy | ||
|
|
||
| # Deploy caddy | ||
| task caddy-deploy | ||
| ``` | ||
|
|
||
| ### pgBackRest | ||
|
|
||
| Create "main" stanza | ||
| ```bash | ||
| docker compose exec -u postgres postgres pgbackrest --stanza=main stanza-create | ||
| ``` | ||
|
|
||
| View backup info | ||
| ```bash | ||
| docker compose exec -u postgres postgres pgbackrest --stanza=main info | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| (file_server_config) { | ||
| encode gzip | ||
| file_server | ||
| } | ||
|
|
||
|
|
||
| {$CADDY_HOST_BACKEND} { | ||
| request_body { | ||
| max_size 10MB | ||
| } | ||
|
|
||
| handle_path /static/* { | ||
| root * /assets/backend/static | ||
| import file_server_config | ||
| } | ||
|
|
||
| handle_path /media/* { | ||
| root * /assets/backend/media | ||
| import file_server_config | ||
| } | ||
|
|
||
| handle { | ||
| reverse_proxy http://web:80 | ||
| } | ||
| } | ||
|
|
||
|
|
||
| {$CADDY_HOST_MANAGER_DASHBOARD} { | ||
| handle { | ||
| try_files {path} /index.html | ||
| root * /assets/manager-dashboard | ||
| import file_server_config | ||
| } | ||
| } | ||
|
|
||
|
|
||
| {$CADDY_HOST_COMMUNITY_DASHBOARD} { | ||
| handle { | ||
| try_files {path} /index.html | ||
| root * /assets/community-dashboard | ||
| import file_server_config | ||
| } | ||
| } |
Submodule community-dashboard
updated
5 files
| +10 −5 | Dockerfile | |
| +11 −13 | app/views/StatsBoard/index.tsx | |
| +1 −1 | backend | |
| +2 −2 | env.ts | |
| +16 −1 | vite.config.ts |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add that we are using https://taskfile.dev/