Skip to content

Feature/deployment to test #132

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: deploy-to-server
name: deploy-to-prod-server

on:
workflow_run:
Expand All @@ -9,7 +9,7 @@ on:
- completed

jobs:
deploy-to-server:
deploy-to-prod-server:
timeout-minutes: 60
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -38,6 +38,7 @@ jobs:
sed -i "s/__PASSWORD__/$PASSWORD/g" .example.env
sed -i "s/__HOST__/$HOST/g" .example.env
sed -i "s/__DB_PORT__/$DB_PORT/g" .example.env
echo "VITE_API_BASE_URL=https://www.dataframetrainer.com:5000" >> .example.env

# todo: do we need both???
cp .example.env .env
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/deploy-to-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: deploy-to-prod-server

on:
workflow_run:
branches:
- 'test'
workflows: ["e2e-tests"]
types:
- completed

jobs:
deploy-to-prod-server:
timeout-minutes: 60
runs-on: ubuntu-latest
env:
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PORT: ${{ secrets.DB_PORT }}
PASSWORD: ${{ secrets.PASSWORD }}
HOST: ${{ secrets.HOST }}
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_DATAFRAMETRAINER_KEY }}
known_hosts: 'just-a-placeholder-to-not-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.DATAFRAMETRAINER_SERVER_IP }} >> ~/.ssh/known_hosts
- name: Set .env file
run: |
sed -i "s/__DB_NAME__/$DB_NAME/g" .example.env
sed -i "s/__DB_USER__/$DB_USER/g" .example.env
sed -i "s/__PASSWORD__/$PASSWORD/g" .example.env
sed -i "s/__HOST__/$HOST/g" .example.env
sed -i "s/__DB_PORT__/$DB_PORT/g" .example.env
echo "VITE_API_BASE_URL=https://www.test.dataframetrainer.com:4000" >> .example.env

# todo: do we need both???
cp .example.env .env
# this is needed since vite/sveltekit rely on this file when running in production mode
cp .example.env ./frontend-svelte/.env
working-directory: ./
- name: Rsync to server
run: rsync -avz . dataframetrainer@${{ secrets.DATAFRAMETRAINER_SERVER_IP}}:/home/dataframetrainer/test/
- name: Run docker compose
run: |
ssh dataframetrainer@${{ secrets.DATAFRAMETRAINER_SERVER_IP}} "cd /home/dataframetrainer/test && make down && make cleanup_prod && make prod_detached"



2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
working-directory: .
run: |
ls -la
docker compose -f docker-compose.test.yml up -d
docker compose -f docker-compose.testing.yml up -d
-
name: Check curl response of backend
run: |
Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ cleanup_prod:
docker rm -f prod-db-fill-or-update-tables
docker image rm -f prod-db-fill-or-update-tables

cleanup_test:
docker rm -f test-frontend-prod
docker image rm -f test-frontend-prod
docker rm -f test-backend
docker image rm -f test-backend
docker rm -f test-db-fill-or-update-tables
docker image rm -f test-db-fill-or-update-tables

cleanup:
docker rm -f dataframetrainer-db-fill-or-update-tables-1
docker rm -f dataframetrainer-frontend-prod-1
Expand All @@ -34,6 +42,12 @@ prod:
prod_detached:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

test:
docker compose -f docker-compose.yml -f docker-compose.test.yml up

test_detached:
docker compose -f docker-compose.yml -f docker-compose.test.yml up -d

dev:
docker compose -f docker-compose.yml -f docker-compose.dev.yml up

Expand All @@ -44,7 +58,7 @@ up:
docker compose -f docker-compose.yml -f docker-compose.dev.yml up

up_test:
docker compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.test.yml up
docker compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.testing.yml up

recreate:
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --force-recreate
9 changes: 8 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
environment:
NODE_ENV: development
ORIGIN: "http://localhost:3000"
API_BASE_URL: "http://localhost:5000"
ports:
# The port of the website
- 5173:5173
Expand All @@ -24,4 +25,10 @@ services:
# This excludes the node_modules folder from docker volume
- /frontend-svelte/node_modules
- /frontend-svelte/.svelte-kit
working_dir: /app
working_dir: /app

adminer:
image: adminer
restart: always
ports:
- 8081:8080
1 change: 1 addition & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
environment:
NODE_ENV: production
ORIGIN: "https://www.dataframetrainer.com"
API_BASE_URL: "https://www.dataframetrainer.com:5000"
ports:
# The port of the website
- 3000:3000
Expand Down
30 changes: 23 additions & 7 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
version: "3.1"
### File only needed for test setup

services:
fill-db-with-test-input:
backend:
ports:
# we use nginx to proxy port 3999 to the API_BASE_URL
- 3999:5000
environment:
ENV: "test"
BACKEND_PORT: 5000

frontend-test:
restart: on-failure
build:
context: ./database/tests_docker
dockerfile: Dockerfile_fill_db_with_test_inputs
volumes:
- ./database/tests_docker/sql:/app/sql
- ./database/tests_docker/fill_for_local_test.py:/app/fill_for_local_test.py
context: ./frontend-svelte
dockerfile: Dockerfile.prod
environment:
NODE_ENV: test
ORIGIN: "https://www.test.dataframetrainer.com"
API_BASE_URL: "https://www.test.dataframetrainer.com:4000"
ports:
# The port of the website
- 4444:3000

volumes:
dataframetrainer_postgres_test:
external: true
11 changes: 11 additions & 0 deletions docker-compose.testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.1"
### File only needed for test setup

services:
fill-db-with-test-input:
build:
context: ./database/tests_docker
dockerfile: Dockerfile_fill_db_with_test_inputs
volumes:
- ./database/tests_docker/sql:/app/sql
- ./database/tests_docker/fill_for_local_test.py:/app/fill_for_local_test.py
13 changes: 3 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ services:
build:
context: backend
dockerfile: Dockerfile
ports:
- 4999:5000
working_dir: /app
volumes:
- ./backend:/app
Expand Down Expand Up @@ -46,14 +44,9 @@ services:
- ./backend/challenges:/challenges
- ./database/sql_scripts:/sql_scripts
- dataframetrainer_postgres:/var/lib/postgresql/data
ports:
- "${DB_PORT}:5432"

adminer:
image: adminer
restart: always
ports:
- 8081:8080
# we do not need this
# ports:
# - "${DB_PORT}:5432"

volumes:
dataframetrainer_postgres:
1 change: 1 addition & 0 deletions frontend-svelte/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ declare module '$env/static/private' {
export const DB_USER: string;
export const DB_PORT: string;
export const DB_NAME: string;
export const API_BASE_URL: string;
}

interface UserProperties {
Expand Down
8 changes: 4 additions & 4 deletions frontend-svelte/src/routes/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const API_BASE_URL = process.env.NODE_ENV === 'production'
// we use nginx as reverse proxy, so it redirects all requests to http://www.dataframetrainer.com:5000 to localhost:4999
? 'https://www.dataframetrainer.com:5000'
: 'http://localhost:4999';
let API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
let NODE_ENV = process.env.NODE_ENV;

export { API_BASE_URL, NODE_ENV };