Skip to content

Commit

Permalink
Dockerize frontend, too (#130)
Browse files Browse the repository at this point in the history
* Dockerize frontend, too

* Update the Makefile according to the new docker compose stuff

* Update check.yaml

* Attempt to fix the check

* Use the example .env file for tests
  • Loading branch information
th0th authored Jan 29, 2023
1 parent fdbf0d1 commit d699ad7
Show file tree
Hide file tree
Showing 25 changed files with 229 additions and 213 deletions.
11 changes: 6 additions & 5 deletions backend/.env.example → .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ CLICKHOUSE_USER=poeticmetric
DEBUG=false
FRONTEND_BASE_URL=https://dev.poeticmetric.com
HOSTED=true
NODE_RED_BASE_URL=
REMOTE_DEBUG=false
REST_API_BASE_URL=https://api.dev.poeticmetric.com
WEBHOOK_URL=
WORKER_COUNT=1

# POSTGRES
Expand All @@ -41,11 +41,12 @@ SENTRY_DSN=
SENTRY_ENVIRONMENT=development

# SMTP
SMTP_HOST=
SMTP_PASSWORD=
SMTP_PORT=
SMTP_USER=
SMTP_HOST=noop
SMTP_PASSWORD=noop
SMTP_PORT=noop
SMTP_USER=noop

# STRIPE
STRIPE_PUBLISHABLE_KEY=noop
STRIPE_SECRET_KEY=noop
STRIPE_WEBHOOK_SIGNING_SECRET=noop
52 changes: 52 additions & 0 deletions .envx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# CLICKHOUSE
CLICKHOUSE_DATABASE=poeticmetric
CLICKHOUSE_HOST=clickhouse
CLICKHOUSE_PASSWORD=poeticmetric
CLICKHOUSE_TCP_PORT=9000
CLICKHOUSE_USER=poeticmetric

# DOCKER COMPOSE
COMPOSE_PROJECT_NAME=poeticmetric-development

# POETICMETRIC
DEBUG=true
FRONTEND_BASE_URL=https://dev.poeticmetric.com
HOSTED=true
NODE_RED_BASE_URL=https://node-red.webgazer.io/poeticmetric
REMOTE_DEBUG=false
REST_API_BASE_URL=https://api.dev.poeticmetric.com
WORKER_COUNT=1

# POSTGRES
POSTGRES_DATABASE=poeticmetric
POSTGRES_HOST=postgres
POSTGRES_PASSWORD=poeticmetric
POSTGRES_PORT=5432
POSTGRES_USER=poeticmetric

# RABBITMQ
RABBITMQ_HOST=rabbitmq
RABBITMQ_PASSWORD=poeticmetric
RABBITMQ_PORT=5672
RABBITMQ_USER=poeticmetric
RABBITMQ_VHOST=poeticmetric

# REDIS
REDIS_HOST=redis
REDIS_PASSWORD=redis
REDIS_PORT=6379

# SENTRY
SENTRY_DSN=https://[email protected]/4504514544599040
SENTRY_ENVIRONMENT=development

# SMTP
SMTP_HOST=email-smtp.eu-west-1.amazonaws.com
SMTP_PASSWORD=BJ+6e13cdMjI6PiGm5dGUeXo7x9tBNBHHYSjzAydACZt
SMTP_PORT=587
SMTP_USER=AKIAQFCOKB32IXJ7WDXE

# STRIPE
STRIPE_PUBLISHABLE_KEY=pk_test_51JsF5eLcgjrGpczs2hzDsONDQlYIsR1iu57vmAec2N4OMjh7w4achSkIb4aCCGea6YgyMKu0XNazacVTIHXzcolX00XcDdVw8l
STRIPE_SECRET_KEY=sk_test_51JsF5eLcgjrGpczseNOFKSWGSMOHkRQIt3CK9okvUytWVXtOrjaKnbkZFeTAsonb9GOsMShsIVkFJoxT9kddBMOC00TRwC5Fcs
STRIPE_WEBHOOK_SIGNING_SECRET=whsec_d612fdd17aadb4f10a2ece1f20bdbac3ee56262c9cb732bf59c96c9efb393c08
9 changes: 4 additions & 5 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ jobs:
uses: actions/checkout@v3

- name: Pull required images
run: docker compose --env-file ./.env.example pull clickhouse postgres rabbitmq
working-directory: backend
run: docker compose pull clickhouse postgres rabbitmq

- name: Build development image
run: make test-build
working-directory: backend

- name: Run tests
run: make test
working-directory: backend
run: |
cp .env.example .env
make test
run-frontend-tests:
if: github.event.pull_request.draft == false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
SENTRY_ENVIRONMENT=${{ inputs.environment }}
SENTRY_ORG=${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }}
STRIPE_API_PUBLISHABLE_KEY=${{ vars.STRIPE_API_PUBLISHABLE_KEY }}
STRIPE_PUBLISHABLE_KEY=${{ vars.STRIPE_PUBLISHABLE_KEY }}
context: frontend
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
/etc/ssl
/.env
18 changes: 0 additions & 18 deletions .vscode/settings.json

This file was deleted.

30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
test:
@export COMPOSE_PROJECT_NAME=poeticmetric-test

@# prepare Postgres database
@printf "Waiting for Postgres...\n"
@docker compose run --rm --entrypoint 'bash -c "wait-for-it -s -q "$${POSTGRES_HOST}":"$${POSTGRES_PORT}" -- echo \"Postgres is ready!\""' rest-api 2> /dev/null
@docker compose exec -- postgres bash -c 'export PGPASSWORD=$${POSTGRES_PASSWORD} && dropdb --if-exists --username=$${POSTGRES_USER} $${POSTGRES_DB}'
@docker compose exec -- postgres bash -c 'export PGPASSWORD=$${POSTGRES_PASSWORD} && createdb --username=$${POSTGRES_USER} $${POSTGRES_DB}'
@docker compose run --rm rest-api migrate-postgres up 2> /dev/null

@# prepare ClickHouse database
@printf "Waiting for ClickHouse...\n"
@docker compose run --rm --entrypoint 'bash -c "wait-for-it -s -q "$${CLICKHOUSE_HOST}":"$${CLICKHOUSE_TCP_PORT}" -- echo \"ClickHouse is ready!\""' rest-api 2> /dev/null
@docker compose exec -- clickhouse bash -c 'clickhouse-client --query "drop database if exists $${CLICKHOUSE_DB};"'
@docker compose exec -- clickhouse bash -c 'clickhouse-client --query "create database $${CLICKHOUSE_DB};"'
@docker compose run --rm rest-api migrate-clickhouse up 2> /dev/null

@# run tests
@docker compose run --rm rest-api run-tests ./... 2> /dev/null

@# drop Postgres database
@docker compose exec -- postgres bash -c 'export PGPASSWORD=$${POSTGRES_PASSWORD} && dropdb --if-exists --username=$${POSTGRES_USER} $${POSTGRES_DB}'

@# drop ClickHouse database
@docker compose exec -- clickhouse bash -c 'clickhouse-client --query "drop database if exists $${CLICKHOUSE_DB};"'

@docker compose down -v 2> /dev/null

test-build:
@docker compose build rest-api 2> /dev/null
2 changes: 0 additions & 2 deletions backend/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ COPY --from=0 /usr/src/poeticmetric/bin/worker /usr/local/bin/poeticmetric-worke

COPY docker-entrypoint.sh /usr/local/bin/

CMD ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["docker-entrypoint.sh"]
32 changes: 0 additions & 32 deletions backend/Makefile

This file was deleted.

39 changes: 0 additions & 39 deletions backend/etc/ingress/dev.poeticmetric.com.nginx

This file was deleted.

2 changes: 1 addition & 1 deletion backend/pkg/env/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
FrontendBaseUrl = "FRONTEND_BASE_URL"
Hosted = "HOSTED"
Instance = "INSTANCE"
NodeRedBaseUrl = "NODE_RED_BASE_URL"
PostgresDatabase = "POSTGRES_DATABASE"
PostgresHost = "POSTGRES_HOST"
PostgresPassword = "POSTGRES_PASSWORD"
Expand All @@ -43,7 +44,6 @@ const (
SmtpUser = "SMTP_USER"
StripeSecretKey = "STRIPE_SECRET_KEY"
StripeWebhookSigningSecret = "STRIPE_WEBHOOK_SIGNING_SECRET"
WebhookUrl = "WEBHOOK_URL"
WorkerCount = "WORKER_COUNT"
WorkerQueues = "WORKER_QUEUES"
)
Expand Down
66 changes: 0 additions & 66 deletions backend/pkg/webhook/main.go

This file was deleted.

4 changes: 2 additions & 2 deletions backend/pkg/worker/send_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type SendWebhookPayload struct {
}

func SendWebhook(dp *depot.Depot, payload *SendWebhookPayload) error {
if env.Get(env.WebhookUrl) == "" {
if env.Get(env.NodeRedBaseUrl) == "" {
return nil
}

Expand Down Expand Up @@ -69,7 +69,7 @@ func sendWebhook(dp *depot.Depot, b []byte) error {
return err
}

_, err = dp.HttpClient().Post(env.Get(env.WebhookUrl), "application/json", bytes.NewBuffer(bodyByteSlice))
_, err = dp.HttpClient().Post(env.Get(env.NodeRedBaseUrl)+"/webhook", "application/json", bytes.NewBuffer(bodyByteSlice))
if err != nil {
return err
}
Expand Down
8 changes: 0 additions & 8 deletions backend/scripts/trigger-reflex-on-change.ps1

This file was deleted.

Loading

0 comments on commit d699ad7

Please sign in to comment.