Skip to content

Commit

Permalink
CI-CD - Made the docker images push to the AMOS organization (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corgam authored May 13, 2024
2 parents 94da656 + 9b24333 commit dcfc07c
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 40 deletions.
90 changes: 75 additions & 15 deletions .github/workflows/deploy_production.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,89 @@
name: Deploy - Production Env.
name: Publish and deploy - Production Env.

on:
push:
tags:
- sprint-**-release

env:
REGISTRY: ghcr.io
IMAGE_NAME: amosproj/amos2024ss04-building-information-enhancer

jobs:
PublishImages:
name: Publish Docker Images
build-and-push-frontend:
name: Builds and publishes the Frontend image
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Login
run: |
echo ${{secrets.PAT}} | docker login ghcr.io -u ${{github.actor}} --password-stdin
- name: Build and Publish
run: |
docker compose build --pull
docker-compose push
- name: Logout
run: docker logout
- 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}}

DeployProductionEnv:
needs: PublishImages
deploy-prod-env:
needs: [build-and-push-frontend, build-and-push-backend]
name: Deploy Image in the Production Environment
runs-on: ubuntu-latest

Expand Down
94 changes: 77 additions & 17 deletions .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,90 @@
name: Deploy - Test Env.
name: Publish and deploy - Test Env.

on:
push:
tags:
- sprint-**-release-candidate

env:
REGISTRY: ghcr.io
IMAGE_NAME: amosproj/amos2024ss04-building-information-enhancer

jobs:
PublishImages:
name: Publish Docker Images
build-and-push-frontend:
name: Builds and publishes the Frontend image
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Login
run: |
echo ${{secrets.PAT}} | docker login ghcr.io -u ${{github.actor}} --password-stdin
- name: Build and Publish
run: |
docker compose build --pull
docker-compose push
- name: Logout
run: docker logout

DeployTestEnv:
needs: PublishImages
name: Deploy Image in the Test Environment
- 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:
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/frontend-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
path: ./frontend/node_modules
key: npm-dependencies-${{ hashFiles('./frontend/package-lock.json') }}

- name: Setup frontend
run: npm ci
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
context: ./frontend
dockerfile: Dockerfile
container_name: react-frontend
image: ghcr.io/corgam/bie-frontend
image: ghcr.io/amosproj/amos2024ss04-building-information-enhancer-frontend
environment:
- HOST=${REACT_FRONTEND_HOST}
- PORT=${REACT_FRONTEND_PORT}
Expand All @@ -19,7 +19,7 @@ services:
context: ./backend/src/BIE.Core
dockerfile: Dockerfile
container_name: backend
image: ghcr.io/corgam/bie-backend
image: ghcr.io/amosproj/amos2024ss04-building-information-enhancer-backend
environment:
- HOST=${BACKEND_HOST}
- PORT=${BACKEND_PORT}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./App.css";

function App() {
return <h1> Building Information Enhancer v.5</h1>;
return <h1> Building Information Enhancer v.6</h1>;
}

export default App;

0 comments on commit dcfc07c

Please sign in to comment.