Skip to content

Added final sprint documentation (#417) #35

Added final sprint documentation (#417)

Added final sprint documentation (#417) #35

name: Publish and deploy - Production Env.
on:
push:
tags:
- sprint-**-release
env:
REGISTRY: ghcr.io
IMAGE_NAME: amosproj/amos2024ss04-building-information-enhancer
STAGE: production
jobs:
build-and-publish:
name: Build and publish -
runs-on: ubuntu-latest
strategy:
matrix:
service:
- name: frontend
context: ./frontend
docker_dir:
- name: api-gateway
context: ./backend
docker_dir: /api-gateway
- name: api-composer
context: ./backend
docker_dir: /src/BIE.Core
- name: datapipeline
context: ./backend
docker_dir: /src/BIE.DataPipeline
- name: sql-database
context: ./backend/sql-database
docker_dir:
- name: metadata-database
context: ./backend/metadata-database
docker_dir:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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 - ${{ matrix.service.name }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.service.name }}
tags: |
type=ref,event=tag
type=sha
type=raw,value=${{ env.STAGE }}
latest
labels: |
stage=${{ env.STAGE }}
- name: Build and Publish Docker Image - ${{ matrix.service.name }}
uses: docker/build-push-action@v5
with:
context: ${{ matrix.service.context }}
file: ${{ matrix.service.context }}${{ matrix.service.docker_dir }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
STAGE=${{ env.STAGE }}
deploy-test-env:
needs: build-and-publish
name: Deploy - 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.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 down -v && docker compose pull && docker compose up -d --remove-orphans --force-recreate && exit"
- name: Cleanup
run: rm -rf ~/.ssh