Release - Sprint 4 (#153) #8
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish and deploy - Production Env. | |
on: | |
push: | |
tags: | |
- sprint-**-release | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: amosproj/amos2024ss04-building-information-enhancer | |
jobs: | |
build-and-publish-frontend: | |
name: Build and publish the Frontend image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
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}} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend | |
tags: | | |
type=ref,event=tag | |
type=sha | |
latest | |
- 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}} | |
build-and-publish-backend-api-gateway: | |
name: Build and publish - API Gateway | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
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}} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-api-gateway | |
tags: | | |
type=ref,event=tag | |
type=sha | |
latest | |
- 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}} | |
build-and-publish-backend-datapipeline: | |
name: Build and publish - Data Pipeline | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
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}} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-datapipeline | |
tags: | | |
type=ref,event=tag | |
type=sha | |
latest | |
- 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}} | |
build-and-publish-backend-sql-database: | |
name: Build and publish - SQL Database | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
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}} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-sql-database | |
tags: | | |
type=ref,event=tag | |
type=sha | |
latest | |
- 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}} | |
deploy-prod-env: | |
needs: | |
[ | |
build-and-publish-frontend, | |
build-and-publish-backend-api-gateway, | |
build-and-publish-backend-datapipeline, | |
build-and-publish-backend-sql-database, | |
] | |
name: Deploy Image in the Production Environment | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{github.ref_name}} | |
- name: Install SSH key | |
run: | | |
install -m 600 -D /dev/null ~/.ssh/id_rsa | |
echo "${{secrets.PROD_ENV_SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa | |
ssh-keyscan -H ${{secrets.PROD_ENV_SSH_HOST}} > ~/.ssh/known_hosts | |
- 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 | |
- 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 | |
run: rm -rf ~/.ssh |