-
Notifications
You must be signed in to change notification settings - Fork 7
experiment: How could it be to deploy using docker only (no kubernetes) #1905
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
Open
hugotiburtino
wants to merge
28
commits into
staging
Choose a base branch
from
deploy-with-docker-only
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
89e7833
feat: add basic files for a deployment only with docker compose
hugotiburtino 094164d
use files in the kratos config instead of base64
hugotiburtino b0cd800
refactor(deploy): add placeholders to staging config for kratos
hugotiburtino 4f6cc4e
fix configuration of nginx
hugotiburtino 8af3836
doc(deploy): give more instructions
hugotiburtino 311ad23
refactor(deploy): use config for nginx as site available
hugotiburtino 5a06d97
chore(deploy-with-docker): improve documentation
hugotiburtino 5e105eb
solution for ssl certificate
hugotiburtino f312de3
Remove unnecessary file and adapt kratos config for staging
hugotiburtino ae5b1dc
format
hugotiburtino 391d07b
Add instructions for set staging db up
hugotiburtino 5a1f9a5
Correct script and minor changes
hugotiburtino 4421b59
fix loading of file and tty for staging db setup
hugotiburtino 274118d
specify subdomain for api
hugotiburtino 60d8db4
modularize deployment files
hugotiburtino 6657754
Add basic files for production deploy
hugotiburtino 09d80ca
minos precisions in docs
hugotiburtino 2b3abb7
fix script for dbsetup
hugotiburtino f9150ae
minor documentation
hugotiburtino be81c93
protect sensitive files from being commited
hugotiburtino 5e0bc4f
feat: add script for dumping anonymized dbs
hugotiburtino 4855ec1
minor adjust to make accessing db in postgres easier
hugotiburtino 7416bc4
block all resquests from unknown hosts
hugotiburtino 416d388
add instruction for db-migration
hugotiburtino 778b41e
Add missing env vars
hugotiburtino 6c3d505
Add script for doing the rocket chat db dump and minor fix
hugotiburtino 6391933
minor instruction regarding importing dumps
hugotiburtino 17b2b79
minor fix in documentation
hugotiburtino 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
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,93 @@ | ||
| # Deployment Instructions with Docker Compose | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Docker | ||
| - Nginx | ||
| - Git | ||
| - GCloud CLI | ||
| - Gsutil | ||
| - unzip | ||
|
|
||
| ## Steps for the deployment | ||
|
|
||
| 1. `git clone https://github.com/serlo/api.serlo.org && cd api.serlo.org/deploy/` | ||
| 2. `cd staging/` or `cd production/` depending on your enviroment. | ||
| 3. Set up Nginx on the host machine using configuration file `nginx.default.conf`. | ||
| 1. First you need to set up SSL certificates (currently, self-signed ones are enough): | ||
| ```console | ||
| $ sudo mkdir -p /etc/nginx/ssl | ||
| $ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ | ||
| -keyout /etc/nginx/ssl/selfsigned.key \ | ||
| -out /etc/nginx/ssl/selfsigned.crt \ | ||
| # uncomment what apply | ||
| # -subj "/CN=*.serlo-staging.dev" | ||
| # -subj "/CN=*.serlo.org" | ||
| ``` | ||
| 2. Then configure the routes: | ||
| ```console | ||
| $ sudo cp nginx.default.conf /etc/nginx/sites-available/default # alternatively use the command `ln` | ||
| $ sudo systemctl restart nginx | ||
| ``` | ||
| 4. Be sure the values at corresponding `.env` and `kratos/config.staging.yml` or `kratos/config.production.yml` (change the values with "PLACEHODER") are correct. | ||
| 5. Deploy using Docker Compose. | ||
| 6. Set the DNS accordingly. At the server, remember set the firewall rules to allow http and https. | ||
|
|
||
| ## Additional steps for STAGING | ||
|
|
||
| ### Serlo DB Setup | ||
|
|
||
| You need to fill up the database with data and set the cronjob for that for every night. | ||
|
|
||
| Set up the Gsutil. You need to authenticate and may use a key of the appropriate service account. | ||
|
|
||
| 1. Go to GC Console -> IAM -> Service Accounts -> choose the dbreader account -> generate a new one | ||
| 2. Put the key in a file `staging_service_account_key.json` in the home directory | ||
| 3. `gcloud auth activate-service-account --key-file ~/staging_service_account_key.json` | ||
| 4. Run `./dbsetup.sh` in host | ||
| 5. Set cron tab to run the dbsetup script every night at 2 am. | ||
|
|
||
| ### DB Migration Cronjob | ||
|
|
||
| Add a crontab in host with the following command (replace the missing values) for 3 am. | ||
|
|
||
| ``` | ||
| docker run --rm --name db-migration --env-file PATH/TO/.env -e SLACK_CHANNEL="PLACEHOLDER" -e SLACK_TOKEN="PLACEHOLDER" --network staging_staging-network ghcr.io/serlo/api.serlo.org/db-migration:PLACEHOLDER | ||
| ``` | ||
|
|
||
| ## Additional steps for PRODUCTION | ||
|
|
||
| ### Serlo DB Dump | ||
|
|
||
| In your first deployment, you will need to import the existing data into mysql and postgres containers. | ||
| Manually dump the production databases. Take a look at `staging/dbsetup.sh` for some inspiration on how to | ||
| import the data. | ||
|
|
||
| Afterwards, You need to set up the cronjob for dumping the database for staging. | ||
|
|
||
| Set up the Gsutil. You need the credentials of a service account in order that the script runs correctly. | ||
|
|
||
| 1. Go to GC Console -> IAM -> Service Accounts -> choose the dbreader account -> generate a new one | ||
| 2. Put the key in a file `production_service_account_key.json` in the home directory | ||
| 3. Set cron tab to run the dbdump script every night at 1 am. | ||
|
|
||
| ### Rocket Chat DB Dump | ||
|
|
||
| In your first deployment, you will need to import the existing data into mongodb container. | ||
|
|
||
| 1. Download the dump from the corresponding bucket in the GC project 'production' | ||
| 2. Run | ||
| ``` | ||
| $ docker compose cp dump-????.gz mongodb:/dump.gz | ||
| $ docker compose exec mongodb mongorestore --archive=dump.gz --gzip | ||
| ``` | ||
|
|
||
| Now, set up a crontab to upload a backup of the data to the bucket at midnight, using the script `mongodbdump.sh`. | ||
|
|
||
| ### DB Migration | ||
|
|
||
| In case of db migration, run the following command in host (replace the missing values). | ||
|
|
||
| ``` | ||
| docker run --rm --name db-migration --env-file PATH/TO/.env -e SLACK_CHANNEL="PLACEHOLDER" -e SLACK_TOKEN="PLACEHOLDER" --network production-network ghcr.io/serlo/api.serlo.org/db-migration:PLACEHOLDER | ||
| ``` | ||
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,191 @@ | ||
| dsn: postgres://serlo:secret@postgres:5432/kratos?sslmode=disable&max_conns=20&max_idle_conns=4 | ||
|
|
||
| serve: | ||
| public: | ||
| base_url: https://kratos.serlo.org | ||
| request_log: | ||
| disable_for_health: true | ||
| admin: | ||
| request_log: | ||
| disable_for_health: true | ||
|
|
||
| selfservice: | ||
| default_browser_return_url: https://serlo.org/ | ||
| allowed_return_urls: | ||
| # TODO: try with wildcard later | ||
| - https://fr.serlo.org/ | ||
| - https://hi.serlo.org/ | ||
| - https://de.serlo.org/ | ||
| - https://ta.serlo.org/ | ||
| - https://en.serlo.org/ | ||
| - https://es.serlo.org/ | ||
| methods: | ||
| password: | ||
| enabled: true | ||
| config: | ||
| haveibeenpwned_enabled: false | ||
| link: | ||
| enabled: true | ||
| config: | ||
| base_url: https://serlo.org/api/.ory/ | ||
| oidc: | ||
| enabled: true | ||
| config: | ||
| base_redirect_uri: https://serlo.org/api/.ory/ | ||
| providers: | ||
| - id: nbp | ||
| provider: generic | ||
| client_id: PLACEHOLDER | ||
| client_secret: PLACEHOLDER | ||
| issuer_url: https://aai.demo.meinbildungsraum.de/realms/nbp-aai | ||
| mapper_url: file:///etc/config/kratos/user_mapper.jsonnet | ||
| - id: vidis | ||
| provider: generic | ||
| client_id: PLACEHOLDER | ||
| client_secret: PLACEHOLDER | ||
| issuer_url: http://PLACEHOLDER | ||
| mapper_url: file:///etc/config/kratos/vidis_user_mapper.jsonnet | ||
|
|
||
| flows: | ||
| error: | ||
| ui_url: https://serlo.org/auth/error | ||
|
|
||
| settings: | ||
| ui_url: https://serlo.org/auth/settings | ||
| privileged_session_max_age: 15m | ||
|
|
||
| recovery: | ||
| enabled: true | ||
| use: link | ||
| ui_url: https://serlo.org/auth/recovery | ||
|
|
||
| verification: | ||
| enabled: true | ||
| use: link | ||
| ui_url: https://serlo.org/auth/verification | ||
|
|
||
| logout: | ||
| after: | ||
| default_browser_return_url: https://serlo.org/auth/login | ||
|
|
||
| login: | ||
| ui_url: https://serlo.org/auth/login | ||
| lifespan: 10m | ||
| after: | ||
| password: | ||
| hooks: | ||
| - hook: require_verified_address | ||
| - hook: web_hook | ||
| config: | ||
| url: https://api.serlo.org/kratos/updateLastLogin | ||
| method: POST | ||
| body: file:///etc/config/kratos/identity_id.jsonnet | ||
| response: | ||
| ignore: true | ||
| oidc: | ||
| default_browser_return_url: https://serlo.org/auth/login | ||
|
|
||
| registration: | ||
| enable_legacy_one_step: true | ||
| lifespan: 10m | ||
| ui_url: https://serlo.org/auth/registration | ||
| after: | ||
| hooks: | ||
| - hook: web_hook | ||
| config: | ||
| url: https://api.serlo.org/kratos/register | ||
| method: POST | ||
| body: file:///etc/config/kratos/identity_id.jsonnet | ||
| auth: | ||
| type: api_key | ||
| config: | ||
| name: x-kratos-key | ||
| value: PLACEHOLDER | ||
| in: header | ||
| - hook: web_hook | ||
| config: | ||
| url: https://PLACEHOLDER | ||
| method: POST | ||
| body: file:///etc/config/kratos/subscribe_newsletter_mapper.jsonnet | ||
| can_interrupt: false | ||
| response: | ||
| ignore: true | ||
| auth: | ||
| type: basic_auth | ||
| config: | ||
| user: serlo | ||
| password: PLACEHOLDER | ||
| oidc: | ||
| default_browser_return_url: https://serlo.org/auth/login | ||
| hooks: | ||
| - hook: web_hook | ||
| config: | ||
| url: https://api.serlo.org/kratos/register | ||
| method: POST | ||
| body: file:///etc/config/kratos/identity_id.jsonnet | ||
| auth: | ||
| type: api_key | ||
| config: | ||
| name: x-kratos-key | ||
| value: PLACEHOLDER | ||
| in: header | ||
| - hook: session | ||
| - hook: web_hook | ||
| config: | ||
| url: https://PLACEHOLDER | ||
| method: POST | ||
| body: file:///etc/config/kratos/subscribe_newsletter_mapper.jsonnet | ||
| can_interrupt: false | ||
| response: | ||
| ignore: true | ||
| auth: | ||
| type: basic_auth | ||
| config: | ||
| user: serlo | ||
| password: PLACEHOLDER | ||
|
|
||
| session: | ||
| lifespan: 720h | ||
|
|
||
| secrets: | ||
| cookie: | ||
| - PLACEHOLDERPLACEHOLDER | ||
|
|
||
| identity: | ||
| default_schema_id: default | ||
| schemas: | ||
| - id: default | ||
| url: file:///etc/config/kratos/identity.schema.json | ||
|
|
||
| courier: | ||
| smtp: | ||
| connection_uri: smtp://PLACEHOLDER | ||
| from_name: Serlo | ||
| from_address: [email protected] | ||
| templates: | ||
| verification: | ||
| valid: | ||
| email: | ||
| subject: http://serlo.org/api/.ory/mail-templates/verification/valid/email.subject.gotmpl | ||
| body: | ||
| html: http://serlo.org/api/.ory/mail-templates/verification/valid/email.body.gotmpl | ||
| plaintext: http://serlo.org/api/.ory/mail-templates/verification/valid/email.body.plaintext.gotmpl | ||
| invalid: | ||
| email: | ||
| subject: http://serlo.org/api/.ory/mail-templates/verification/invalid/email.subject.gotmpl | ||
| body: | ||
| html: http://serlo.org/api/.ory/mail-templates/verification/invalid/email.body.gotmpl | ||
| plaintext: http://serlo.org/api/.ory/mail-templates/verification/invalid/email.body.plaintext.gotmpl | ||
| recovery: | ||
| valid: | ||
| email: | ||
| subject: http://serlo.org/api/.ory/mail-templates/recovery/valid/email.subject.gotmpl | ||
| body: | ||
| html: http://serlo.org/api/.ory/mail-templates/recovery/valid/email.body.gotmpl | ||
| plaintext: http://serlo.org/api/.ory/mail-templates/recovery/valid/email.body.plaintext.gotmpl | ||
| invalid: | ||
| email: | ||
| subject: http://serlo.org/api/.ory/mail-templates/recovery/invalid/email.subject.gotmpl | ||
| body: | ||
| html: http://serlo.org/api/.ory/mail-templates/recovery/invalid/email.body.gotmpl | ||
| plaintext: http://serlo.org/api/.ory/mail-templates/recovery/invalid/email.body.plaintext.gotmpl |
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.
Uh oh!
There was an error while loading. Please reload this page.