Skip to content

Commit

Permalink
Worked on the API URL changing based on the environment (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corgam authored May 28, 2024
2 parents bcc904a + 2a01381 commit 6bbce90
Show file tree
Hide file tree
Showing 19 changed files with 491 additions and 119 deletions.
14 changes: 9 additions & 5 deletions .env
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
### Config ###
ENVIRONMENT_STAGE=Development
### CONFIG ###

### Ports and hosts ###
# The environment stage set for individual services
ENVIRONMENT_STAGE=development
# The tag used for pulling the docker images
DOCKER_COMPOSE_IMAGES_TAG=latest

### HOSTS & PORTS ###

# Frontend
FRONTEND_HOST=frontend
FRONTEND_PORT=80

# Backend
BACKEND_HOST=api-gateway
BACKEND_PORT=8081
VITE_BACKEND_HOST=localhost
VITE_BACKEND_PORT=8081
16 changes: 16 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### CONFIG ###

# The environment stage set for individual services
ENVIRONMENT_STAGE=production
# The tag used for pulling the docker images
DOCKER_COMPOSE_IMAGES_TAG=production

### HOSTS & PORTS ###

# Frontend
FRONTEND_HOST=frontend
FRONTEND_PORT=80

# Backend
VITE_BACKEND_HOST=prod.amos.b-ci.de
VITE_BACKEND_PORT=8081
16 changes: 16 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### CONFIG ###

# The environment stage set for individual services
ENVIRONMENT_STAGE=test
# The tag used for pulling the docker images
DOCKER_COMPOSE_IMAGES_TAG=test

### HOSTS & PORTS ###

# Frontend
FRONTEND_HOST=frontend
FRONTEND_PORT=80

# Backend
VITE_BACKEND_HOST=test.amos.b-ci.de
VITE_BACKEND_PORT=8081
77 changes: 47 additions & 30 deletions .github/workflows/deploy_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: amosproj/amos2024ss04-building-information-enhancer
STAGE: production

jobs:
build-and-publish-frontend:
Expand All @@ -18,14 +19,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{github.ref_name}}
ref: ${{ github.ref_name }}

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{env.REGISTRY}}
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
Expand All @@ -35,16 +36,20 @@ jobs:
tags: |
type=ref,event=tag
type=sha
latest
type=raw,value=${{ env.STAGE }}
labels: |
stage=${{ env.STAGE }}
- name: Build and Publish Docker Images
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
STAGE: ${{ env.STAGE }}
build-and-publish-backend-api-gateway:
name: Build and publish - API Gateway
Expand All @@ -54,14 +59,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{github.ref_name}}
ref: ${{ github.ref_name }}

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{env.REGISTRY}}
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
Expand All @@ -71,16 +76,20 @@ jobs:
tags: |
type=ref,event=tag
type=sha
latest
type=raw,value=${{ env.STAGE }}
labels: |
stage=${{ env.STAGE }}
- name: Build and Publish Docker Images
uses: docker/build-push-action@v5
with:
context: ./backend/src/BIE.Core
file: ./backend/src/BIE.Core/Dockerfile
push: true
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
STAGE: ${{ env.STAGE }}
build-and-publish-backend-datapipeline:
name: Build and publish - Data Pipeline
Expand All @@ -90,14 +99,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{github.ref_name}}
ref: ${{ github.ref_name }}

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{env.REGISTRY}}
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
Expand All @@ -107,16 +116,20 @@ jobs:
tags: |
type=ref,event=tag
type=sha
latest
type=raw,value=${{ env.STAGE }}
labels: |
stage=${{ env.STAGE }}
- name: Build and Publish Docker Images
uses: docker/build-push-action@v5
with:
context: ./backend/src/BIE.DataPipeline
file: ./backend/src/BIE.DataPipeline/Dockerfile
push: true
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
STAGE: ${{ env.STAGE }}
build-and-publish-backend-sql-database:
name: Build and publish - SQL Database
Expand All @@ -126,14 +139,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{github.ref_name}}
ref: ${{ github.ref_name }}

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{env.REGISTRY}}
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
Expand All @@ -143,16 +156,20 @@ jobs:
tags: |
type=ref,event=tag
type=sha
latest
type=raw,value=${{ env.STAGE }}
labels: |
stage=${{ env.STAGE }}
- name: Build and Publish Docker Images
uses: docker/build-push-action@v5
with:
context: ./backend/database
file: ./backend/database/Dockerfile
push: true
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
STAGE: ${{ env.STAGE }}
deploy-prod-env:
needs:
Expand All @@ -162,7 +179,7 @@ jobs:
build-and-publish-backend-datapipeline,
build-and-publish-backend-sql-database,
]
name: Deploy Image in the Production Environment
name: Deploy Docker Images in the Production Environment
runs-on: ubuntu-latest

steps:
Expand All @@ -178,7 +195,7 @@ jobs:
- name: Copy necessary files
run: |
scp ./docker-compose.yml ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}}:/var/lib/bie
scp ./.env ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}}:/var/lib/bie
scp ./.env.production ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}}:/var/lib/bie/.env
- name: Connect and Pull
run: ssh ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}} "cd /var/lib/bie && docker compose pull && docker compose up -d --remove-orphans && exit"
- name: Cleanup
Expand Down
Loading

0 comments on commit 6bbce90

Please sign in to comment.