Skip to content

CI-CD - Made the docker images push to the AMOS organization (#91) #4

CI-CD - Made the docker images push to the AMOS organization (#91)

CI-CD - Made the docker images push to the AMOS organization (#91) #4

Workflow file for this run

name: Publish and deploy - Test Env.
on:
push:
tags:
- sprint-**-release-candidate
env:
REGISTRY: ghcr.io
IMAGE_NAME: amosproj/amos2024ss04-building-information-enhancer
jobs:
build-and-push-frontend:
name: Builds and publishes 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: .
file: ./frontend/Dockerfile
push: true
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
build-and-push-backend:
name: Builds and publishes the Backend 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 }}-backend
tags: |
type=ref,event=tag
type=sha
latest
- name: Build and Publish Docker Images
uses: docker/build-push-action@v5
with:
context: .
file: ./backend/Dockerfile
push: true
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
deploy-test-env:
needs: [build-and-push-frontend, build-and-push-backend]
name: Deploy Docker Images in the Test Environment
runs-on: ubuntu-latest
steps:
- name: Install SSH keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{secrets.TEST_ENV_SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{secrets.TEST_ENV_SSH_HOST}} > ~/.ssh/known_hosts
- name: Connect and Pull
run: ssh ${{secrets.TEST_ENV_SSH_USER}}@${{secrets.TEST_ENV_SSH_HOST}} "cd /var/lib/bie && docker compose pull && docker compose up -d && exit"
- name: Cleanup
run: rm -rf ~/.ssh