Skip to content

Refactor AnalySim Docker deployment infrastructure - #151

Open
mohab-elshamy wants to merge 2 commits into
developfrom
deployment-infrastructure
Open

mohab-elshamy wants to merge 2 commits into
developfrom
deployment-infrastructure

Conversation

@mohab-elshamy

Copy link
Copy Markdown
Collaborator

Summary

This PR refactors AnalySim’s Docker deployment into a simpler, production-oriented Compose setup. It separates the ASP.NET Core backend, Angular/JupyterLite frontend, PostgreSQL database, one-shot migrations, backups, and Nginx/Certbot responsibilities into clear services, while keeping runtime configuration in a single .env file and persistent state under a user-configurable data directory.

Changes

  • Splits deployment into dedicated PostgreSQL, backend, frontend/Nginx, migration, backup, and Certbot services.
  • Adds separate Dockerfiles for the ASP.NET Core backend, Nginx frontend, and PostgreSQL backup service.
  • Moves Angular and JupyterLite builds into the frontend/Nginx image.
  • Keeps the backend image .NET-only and safe to publish without baked production secrets.
  • Adds a one-shot EF Core migration container.
  • Serves Angular/JupyterLite static files directly from Nginx and reverse-proxies /api/ to the backend.
  • Simplifies runtime configuration to a single .env file.
  • Keeps persistent data, backups, and certificates under a user-configurable ANALYSIM_DATA_ROOT.
  • Updates deployment documentation and removes obsolete legacy Docker files.

Minimal Deploy Steps

cp .env.example .env
# edit .env: ANALYSIM_DATA_ROOT, domain, DB password/connection string, JWT secret, email settings

export ANALYSIM_DATA_ROOT=/path/to/persistent/analysim-data
mkdir -p "$ANALYSIM_DATA_ROOT"/{postgres/data,postgres/certs,backups,certbot/conf,certbot/www}

# add PostgreSQL TLS cert/key under:
# $ANALYSIM_DATA_ROOT/postgres/certs/server.crt
# $ANALYSIM_DATA_ROOT/postgres/certs/server.key

docker compose --env-file .env build
docker compose --env-file .env up -d

@cengique cengique left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing such a comprehensive overhaul of the deployment system. I see many good features, but I also have some suggestions to fix.

I marked some suggestions specifically, but I got stuck in the first Docker run for getting the Let's Encrypt cert:

$ sudo docker run --rm      -v "$ANALYSIM_DATA_ROOT/certbot/conf:/etc/letsencrypt"      -v "$ANALYSIM_DATA_ROOT/certbot/www:/var/www/certbot"      certbot/certbot certonly      --webroot      --webroot-path /var/www/certbot      -d "localhost"
[sudo] password for cengiz: 
Unable to find image 'certbot/certbot:latest' locally
latest: Pulling from certbot/certbot
e6f31ffc071e: Pull complete 
9010581fffd4: Pull complete 
bfac9e75463e: Pull complete 
426f169c5b37: Pull complete 
500b30537bf5: Pull complete 
c37269114a8b: Pull complete 
5e4ba5eb6a5b: Pull complete 
0c77a7cefcb3: Pull complete 
f1e126553701: Pull complete 
bb95bb741cc3: Pull complete 
cc6a5902e005: Pull complete 
Digest: sha256:f70ad0adbb7e117f0fe42a63c553f28ea451edabc0148757b6efcd9735acaa20
Status: Downloaded newer image for certbot/certbot:latest
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Skipped user interaction because Certbot doesn't appear to be running in a terminal. You should probably include --non-interactive or --force-interactive on the command line.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at:
https://letsencrypt.org/documents/LE-SA-v1.8-July-06-2026.pdf
You must agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: An unexpected error occurred:
EOFError
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

Comment thread .env.example
POSTGRES_USER=analysim
POSTGRES_PASSWORD=replace-with-a-long-random-password

DB_CONNECTION_STRING=User ID=analysim;Password=replace-with-a-long-random-password;Server=postgres;Port=5432;Database=analysim;Pooling=true;SSL Mode=Require;Trust Server Certificate=true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already provide the POSTGRES variables above, the connection string is redundant. Either remove this or the previous variables.

Comment thread .env.example
ANALYSIM_DOMAIN=localhost
ANALYSIM_IMAGE_TAG=latest

TLS_CERT_PATH=/etc/letsencrypt/live/localhost/fullchain.pem

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought these were under the data/ folder according to the README

Comment thread .env.example
JWT_ISSUER=AnalySim
JWT_AUDIENCE=https://localhost
JWT_SECRET=replace-with-a-long-random-secret
CLIENT_BASE_URL=https://localhost

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the same as DOMAIN above? or is this only for local runs?

Comment thread .env.example
CLIENT_BASE_URL=https://localhost
ALLOWED_HOSTS=*
ADMIN_USER=ADMIN
REGISTRATION_CODE=replace-with-registration-code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may have more than one registration code

Comment thread deploy/README.md
Expected layout:

```text
$ANALYSIM_DATA_ROOT/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need some of these to be automatically created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants