Included the new api-gateway inside the docker compose #12
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 | |
branches: | |
- CI-CD | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: amosproj/amos2024ss04-building-information-enhancer | |
STAGE: production | |
jobs: | |
build-and-publish: | |
name: Build and publish Docker images | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- 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 | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-api-gateway | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-datapipeline | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-sql-database | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-metadata-database | |
tags: | | |
type=ref,event=tag | |
type=sha | |
type=raw,value=${{ env.STAGE }} | |
labels: | | |
stage=${{ env.STAGE }} | |
- name: Build and push images using bake | |
uses: docker/bake-action@v4 | |
with: | |
files: | | |
./docker-bake.hcl | |
${{ steps.meta.outputs.bake-file }} | |
push: true | |
env: | |
STAGE: ${{ env.STAGE }} | |
MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGO_INITDB_ROOT_USERNAME }} | |
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_INITDB_ROOT_PASSWORD }} | |
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 pull && docker compose up -d --remove-orphans && exit" | |
- name: Cleanup | |
run: rm -rf ~/.ssh |