Skip to content
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

[WIP] Fix Docker #1146

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Include specific files
!/yarn.lock
!/.eslintrc.json
!/eslint.config.js
!/.gitignore
!/babel.config.json
!/Dockerfile
Expand Down
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ JETSTREAM_AUTH_OTP_SECRET=''

# JETSTREAM URLS
# If developing, then these will be localhost
# If running locally but not developing the platform, use port `:3333` for all of these
JETSTREAM_CLIENT_URL='http://localhost:4200/app'
# For JETSTREAM_CLIENT_URL ,change to port 4200 for development of the react client
JETSTREAM_CLIENT_URL='http://localhost:3333/app'
JETSTREAM_SERVER_DOMAIN='localhost:3333'
JETSTREAM_SERVER_URL='http://localhost:3333'
JETSTREAM_POSTGRES_DBURI='postgres://postgres@localhost:5432/postgres'

# Used in landing page to redirect to the correct URL
# If running locally but not developing the platform, use port `:3333` for all of these
NX_PUBLIC_CLIENT_URL='http://localhost:4200/app'
# For NX_PUBLIC_CLIENT_URL ,change to port 4200 for development of the react client
NX_PUBLIC_CLIENT_URL='http://localhost:3333/app'
NX_PUBLIC_SERVER_URL='http://localhost:3333'

# OAUTH FOR LOGGING IN TO THE APP
Expand Down Expand Up @@ -103,6 +103,8 @@ NX_ADD_PLUGINS=false

# Billing related keys
NX_PUBLIC_BILLING_ENABLED=''
STRIPE_API_KEY=''
STRIPE_WEBHOOK_SECRET=''
NX_PUBLIC_STRIPE_PUBLIC_KEY=''
NX_PUBLIC_STRIPE_PRO_ANNUAL_PRICE_ID=''
NX_PUBLIC_STRIPE_PRO_MONTHLY_PRICE_ID=''
52 changes: 50 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
name: Checkout [master]
name: Checkout [main]
with:
fetch-depth: 0

Expand Down Expand Up @@ -58,6 +58,54 @@ jobs:
name: dist-artifacts
path: dist

test-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout [main]
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'

# This is annoying since we have to run it here and in docker container
# it is used for the .env config - maybe there is a better way to do this?
- name: install dependencies
run: yarn install --frozen-lockfile

- name: generate .env file
run: yarn scripts:generate-env --silent

- name: Build Docker image
run: docker build -t jetstream-app .

- name: Start containers
run: docker compose -f docker-compose.yml up -d

- name: Wait for containers
run: |
echo "Waiting for containers to be healthy..."
timeout 30 bash -c 'until docker compose ps | grep -q "healthy"; do sleep 1; done'

- name: Check containers
run: docker compose ps

- name: Test API endpoints
run: |
echo "Testing API endpoints..."
curl --fail --retry 5 --retry-delay 2 http://localhost:3333/healthz

- name: Show logs on failure
if: failure()
run: docker compose logs

- name: Cleanup
if: always()
run: docker compose down -v

# e2e tests only runs if build passes, since it uses production build to run tests
e2e:
needs: build-and-test
Expand Down Expand Up @@ -104,7 +152,7 @@ jobs:

steps:
- uses: actions/checkout@v4
name: Checkout [master]
name: Checkout [main]
with:
fetch-depth: 0

Expand Down
24 changes: 16 additions & 8 deletions scripts/generate.env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dotenv from 'dotenv';
import crypto from 'node:crypto';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { chalk, fs, path, question } from 'zx'; // https://github.com/google/zx
import { argv, chalk, fs, path, question } from 'zx'; // https://github.com/google/zx

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand All @@ -17,8 +17,10 @@ function generateRandomBase64(size = 32) {

const exampleEnvFile = fs.readFileSync(inputFilename, 'utf8');

const silent = argv.silent;

// check if .env file exists, if so ask the user if they want to overwrite it or abort
if (fs.existsSync(inputFilename)) {
if (!silent && fs.existsSync(outputFilename)) {
console.log(chalk.yellow(`.env file already exists.`));
const response = await question('Overwrite? (y/N)? ');
if (!response || response.toLocaleLowerCase() !== 'y') {
Expand All @@ -27,15 +29,21 @@ if (fs.existsSync(inputFilename)) {
}
}

const clientUrl = await question('Are you going to developing on the codebase (determines ports to use)? (y/N) ').then((response) =>
(response || '').toLocaleLowerCase() === 'y' ? 'http://localhost:4200/app' : 'http://localhost:3333/app'
);
let clientUrl = 'http://localhost:3333/app';
if (!silent) {
clientUrl = await question('Are you going to developing on the codebase (determines ports to use)? (y/N) ').then((response) =>
(response || '').toLocaleLowerCase() === 'y' ? 'http://localhost:4200/app' : 'http://localhost:3333/app'
);
}

console.log(chalk.green('Client url set to:'), clientUrl);

const enableExampleUser = await question('Would you like to enable the example user? (Y/n) ').then((response) =>
!response || (response || '').toLocaleLowerCase() === 'y' ? 'true' : 'false'
);
let enableExampleUser = 'true';
if (!silent) {
enableExampleUser = await question('Would you like to enable the example user? (Y/n) ').then((response) =>
!response || (response || '').toLocaleLowerCase() === 'y' ? 'true' : 'false'
);
}

const replacements = [
['JETSTREAM_CLIENT_URL=', `JETSTREAM_CLIENT_URL='${clientUrl}'`],
Expand Down
Loading