From abf4af08012a99196735cc24ee97db7cb4d69a08 Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Mon, 13 May 2024 15:38:37 +0200 Subject: [PATCH 1/4] CI-CD - Made the docker images push to the AMOS organization Signed-off-by: Emil Balitzki --- .github/workflows/deploy_production.yml | 90 +++++++++++++++++++---- .github/workflows/deploy_test.yml | 94 ++++++++++++++++++++----- .github/workflows/frontend-CI.yml | 9 ++- docker-compose.yml | 4 +- 4 files changed, 158 insertions(+), 39 deletions(-) diff --git a/.github/workflows/deploy_production.yml b/.github/workflows/deploy_production.yml index 6fe2ffbc..40d27a7c 100644 --- a/.github/workflows/deploy_production.yml +++ b/.github/workflows/deploy_production.yml @@ -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 diff --git a/.github/workflows/deploy_test.yml b/.github/workflows/deploy_test.yml index 139294e8..7365dd58 100644 --- a/.github/workflows/deploy_test.yml +++ b/.github/workflows/deploy_test.yml @@ -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: diff --git a/.github/workflows/frontend-CI.yml b/.github/workflows/frontend-CI.yml index 7b247076..56d33c1c 100644 --- a/.github/workflows/frontend-CI.yml +++ b/.github/workflows/frontend-CI.yml @@ -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: node_modules + key: npm-dependencies-${{ hashFiles('package-lock.json') }} - name: Setup frontend run: npm ci diff --git a/docker-compose.yml b/docker-compose.yml index a1250662..43c53fb1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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} @@ -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} From 65062b3fbe91c209303af884526b45d17ffbcb9e Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Mon, 13 May 2024 15:39:43 +0200 Subject: [PATCH 2/4] Frontend CI/CD test Signed-off-by: Emil Balitzki --- frontend/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 67cbe78b..adf61548 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,7 +1,7 @@ import "./App.css"; function App() { - return

Building Information Enhancer v.5

; + return

Building Information Enhancer v.6

; } export default App; From fe09e87827df1787a64e39208fd47acc5c80e7ae Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Mon, 13 May 2024 15:43:35 +0200 Subject: [PATCH 3/4] Frontend CI/CD cache fix Signed-off-by: Emil Balitzki --- .github/workflows/frontend-CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend-CI.yml b/.github/workflows/frontend-CI.yml index 56d33c1c..55713519 100644 --- a/.github/workflows/frontend-CI.yml +++ b/.github/workflows/frontend-CI.yml @@ -20,7 +20,7 @@ jobs: uses: actions/cache@v4 with: path: node_modules - key: npm-dependencies-${{ hashFiles('package-lock.json') }} + key: npm-dependencies-${{ hashFiles('./frontend/package-lock.json') }} - name: Setup frontend run: npm ci From 9b243334ded2e8413d16753d74b7144655b5f177 Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Mon, 13 May 2024 15:46:04 +0200 Subject: [PATCH 4/4] Frontend CI/CD cache fix 2 Signed-off-by: Emil Balitzki --- .github/workflows/frontend-CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend-CI.yml b/.github/workflows/frontend-CI.yml index 55713519..8027af59 100644 --- a/.github/workflows/frontend-CI.yml +++ b/.github/workflows/frontend-CI.yml @@ -19,7 +19,7 @@ jobs: - name: Cache dependencies uses: actions/cache@v4 with: - path: node_modules + path: ./frontend/node_modules key: npm-dependencies-${{ hashFiles('./frontend/package-lock.json') }} - name: Setup frontend