DevLeoko / license-gate

License and API key management tool and validation API for developers
https://licensegate.io
Other
39 stars 11 forks source link

feat(container): implement docker and docker compose #3

Closed CurlyBytes closed 4 months ago

CurlyBytes commented 4 months ago

add caddy for reverse proxy add phpymadmin to check the database add nginx for the frontend

Hopefuls commented 4 months ago

Great, have tested this on a vm, facing some issues but seems to work so far:

  1. The tool within the API named "Prisma" will fail and kill the whole api container if it isn't able to connect to the database: I suggest adding an artifical delay (such as simply sleep) for 30-40 seconds to wait for the mysql database to load up fully. Alternatively something that checks for the state of the database? Bit overkill but just adding a delay should be enough.

  2. Docker-compose complains about the caddy network not existing, removing it from the docker-compose test-wise causes it to break with the following error:

{"level":"warn","ts":1721809389.340229,"logger":"docker-proxy","msg":"Container is not in same network as caddy","container":"83440556ccf194a0842256f5fdecd2f032723534766d3874b393755fa51fe7c7","container id":"83440556ccf194a0842256f5fdecd2f032723534766d3874b393755fa51fe7c7"}

So the use of the internal network didn't work quite yet, but should be easy to fix.

  1. Since LicenseGate is using sveltekit, this may cause issues when directly visiting links as Sveltekit requires visiting the index.html always, doesn't matter which path is being visited.

This can be easily fixed by adding a nginx configuration for the location that always forwards the request to the index.html:

    location / {
      try_files $uri $uri/ /index.html =404;
    }

So when you're serving the files using nginx, make sure to also include this in an configuration file.

  1. There's some issue with caddy seemingly changing the cors header settings? Causing the connection to fail? Causing sign up to fail: image

Unsure what the issue is in this case, as it doesn't seem to use the correct settings there. This should be the correct settings reported by the backend: image

Possibly an issue with caddy?

The environment variables used:

SMTP_HOST=mail.hopefuls.de
SMTP_USERNAME=licensegate@hopefuls.de
SMTP_PASSWORD=redacted
SMTP_SENDER=LicenseGate <licensegate@hopefuls.de>
JWT_SECRET=secret
RECAPTCHA_SECRET_KEY=redacted
PUBLIC_BACKEND_URL=https://licensegate-api.direct.hopefuls.de
PUBLIC_FRONTEND_URL=https://licensegate.direct.hopefuls.de
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=mydb
MYSQL_USER=user
MYSQL_PASSWORD=password
BACKEND_FQDN=licensegate-api.direct.hopefuls.de
FROTNEND_FQDN=licensegate.direct.hopefuls.de
CurlyBytes commented 4 months ago

Great, have tested this on a vm, facing some issues but seems to work so far:

  1. The tool within the API named "Prisma" will fail and kill the whole api container if it isn't able to connect to the database: I suggest adding an artifical delay (such as simply sleep) for 30-40 seconds to wait for the mysql database to load up fully. Alternatively something that checks for the state of the database? Bit overkill but just adding a delay should be enough.
  2. Docker-compose complains about the caddy network not existing, removing it from the docker-compose test-wise causes it to break with the following error:

{"level":"warn","ts":1721809389.340229,"logger":"docker-proxy","msg":"Container is not in same network as caddy","container":"83440556ccf194a0842256f5fdecd2f032723534766d3874b393755fa51fe7c7","container id":"83440556ccf194a0842256f5fdecd2f032723534766d3874b393755fa51fe7c7"}

So the use of the internal network didn't work quite yet, but should be easy to fix.

  1. Since LicenseGate is using sveltekit, this may cause issues when directly visiting links as Sveltekit requires visiting the index.html always, doesn't matter which path is being visited.

This can be easily fixed by adding a nginx configuration for the location that always forwards the request to the index.html:

    location / {
      try_files $uri $uri/ /index.html =404;
    }

So when you're serving the files using nginx, make sure to also include this in an configuration file.

  1. There's some issue with caddy seemingly changing the cors header settings? Causing the connection to fail? Causing sign up to fail: image

Unsure what the issue is in this case, as it doesn't seem to use the correct settings there. This should be the correct settings reported by the backend: image

Possibly an issue with caddy?

The environment variables used:

SMTP_HOST=mail.hopefuls.de
SMTP_USERNAME=licensegate@hopefuls.de
SMTP_PASSWORD=redacted
SMTP_SENDER=LicenseGate <licensegate@hopefuls.de>
JWT_SECRET=secret
RECAPTCHA_SECRET_KEY=redacted
PUBLIC_BACKEND_URL=https://licensegate-api.direct.hopefuls.de
PUBLIC_FRONTEND_URL=https://licensegate.direct.hopefuls.de
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=mydb
MYSQL_USER=user
MYSQL_PASSWORD=password
BACKEND_FQDN=licensegate-api.direct.hopefuls.de
FROTNEND_FQDN=licensegate.direct.hopefuls.de

This is now been resolve, this is due to caddy is already using the port 80 and 443, while the nginx in the dockerfile is also using port 80, i added custom port in the docker file and nginx config to resolve the flaky registration

Hopefuls commented 4 months ago

Cool, looks great to me, tried running it once more:

LGTM

@DevLeoko if you want to make a final look at it, then merge if you're ready.

Accessible on https://licensegate-secondary.direct.hopefuls.de/ if want to test it

(Also maybe create a development branch for others to test first)

Hopefuls commented 4 months ago

Nevermind didn't work

CurlyBytes commented 4 months ago

Nevermind didn't work

Yup thats why i expose them

Hopefuls commented 4 months ago

Making a final deployment test to ensure full functionality

Hopefuls commented 4 months ago

Yup tested, works entirely fine now on a fresh install too.

Documentation will be created afterwards

DevLeoko commented 4 months ago

Thanks a lot @CurlyBytes and @Hopefuls for contributing!

CurlyBytes commented 3 months ago

Thank you everyone @DevLeoko and @Hopefuls , i will be submitting again in the future, i love the tool thank you!