From bcf84ed903c625aecac10d201070f0bb74109b5d Mon Sep 17 00:00:00 2001 From: Emilorv Date: Sun, 30 Mar 2025 23:34:15 +0200 Subject: [PATCH] sync changes with other repository --- .github/workflows/deploy.yml | 36 ++++++++++++++++++++++ .github/workflows/update_primary_nginx.yml | 11 ++++--- docker-compose.yml | 12 +++++--- 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1570f22 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,36 @@ +name: Deploy to TDT4242 server development + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + deploy: + runs-on: self-hosted + env: + REPO_NAME: ${{ github.event.repository.name }} + COMPOSE_FILE: "docker-compose.yml" + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Dotenv Action + uses: falti/dotenv-action@v1.1.4 + with: + export-variables: true + keys-case: bypass + + - name: Check status of config file + run: | + env + docker compose version + cd $GITHUB_WORKSPACE + docker compose -f $COMPOSE_FILE --verbose config && printf "OK\n" || exit 1 + + - name: Build and run docker image + run: docker compose -f $COMPOSE_FILE up --force-recreate --build -d + + - name: Verify that gateway is available + run: docker ps diff --git a/.github/workflows/update_primary_nginx.yml b/.github/workflows/update_primary_nginx.yml index b11c262..f3edade 100644 --- a/.github/workflows/update_primary_nginx.yml +++ b/.github/workflows/update_primary_nginx.yml @@ -1,4 +1,4 @@ -name: UNFINISHED - setup nginx from the configuration file +name: Setup nginx from the configuration file on: workflow_dispatch: @@ -19,16 +19,17 @@ jobs: - name: Check environment variables run: env - #Doesn't work properly, envsubst replaces all instances of $variable and ${variable}, but we want to keep e.g., $host as nginx variables - name: Create temporary nginx config file - run: envsubst '$http_host, $remote_addr, $proxy_add_x_forwarded_for' < ./nginx_template.txt > temp_default.conf - # Maybe look at https://www.baeldung.com/linux/envsubst-command to get an idea + run: envsubst '${DEV_PORT_PREFIX}, ${STAG_PORT_PREFIX}, ${PROD_PORT_PREFIX}, ${GATEWAY_POSTFIX},' < ./nginx_template.txt > temp_default.conf - name: user of runner run: whoami - name: Copy temporary file to correct place - run: cp temp_default.conf /etc/nginx/conf.d/nginx_securefit.conf + run: sudo cp temp_default.conf /etc/nginx/conf.d/nginx_securefit.conf - name: Show nginx file run: cat /etc/nginx/conf.d/nginx_securefit.conf + + - name: Restart NGINX + run: sudo systemctl reload nginx \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 79fd232..694ccd4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,9 +10,11 @@ services: build: context: backend/ dockerfile: Dockerfile - network: host #Need to expose it during setup, then it is isolated during running + network: host networks: backend_bridge: + ports: + - ${PROD_PORT_PREFIX}4:8000 volumes: - backend_vol:/app @@ -21,9 +23,11 @@ services: build: context: frontend/ dockerfile: Dockerfile - network: host #Need to expose it during setup, then it is isolated during running - #environment: - # PUBLIC_URL: "http://tdt4242-${GROUP_ID}.idi.ntnu.no/prod/public" + network: host + environment: + PUBLIC_URL: "http://tdt4242-${GROUP_ID}.idi.ntnu.no/prod/public" + ports: + - ${PROD_PORT_PREFIX}5:3000 networks: backend_bridge: