From 4551a799ecc7736a39cbe375ce2340289cd62a63 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Fri, 30 May 2025 16:48:34 -0400 Subject: [PATCH 01/20] add docker-file --- .dockerignore | 4 ++++ Dockerfile | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..21c6f1a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +npm-debug.log +.git +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9a9be8e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18 + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +EXPOSE 3000 + +CMD ["node", "app.js"] \ No newline at end of file From f468b6d62baf6fa7e8f334282247f5b5dbd84360 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 00:13:36 -0400 Subject: [PATCH 02/20] minimal correction on dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9a9be8e..c6ce137 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,6 @@ RUN npm install COPY . . -EXPOSE 3000 +EXPOSE 3001 CMD ["node", "app.js"] \ No newline at end of file From 6600d64179471a39a07c12302ee9802340ab1591 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 19:54:32 -0400 Subject: [PATCH 03/20] minimal corrections on cicd --- .github/workflows/ci-cd.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/ci-cd.yaml diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml new file mode 100644 index 0000000..bbfa89d --- /dev/null +++ b/.github/workflows/ci-cd.yaml @@ -0,0 +1,23 @@ +name: Demo API CI/CD + +on: + workflow_dispatch: + pull_request: + branches: [ main, develop ] + push: + branches: [ main ] + +jobs: + call-reusable-workflow: + uses: gbh-recruitment/ismael-ortiz-montero-ismaelortiz87-2025-5-29-senior-devops-challenge/.github/workflows/standard-docker-build-deploy.yml@main + with: + app_name: "api" + dockerfile_path: "Dockerfile" + helm_chart_repo: "gbh-recruitment/ismael-ortiz-montero-ismaelortiz87-2025-5-29-senior-devops-challenge" + helm_chart_path: "part_2/helm/generic-web-chart" + helm_release_name: "demo-api" + k8s_namespace: "gbh" + deploy_on_main: true + secrets: + KUBECONFIG: ${{ secrets.KUBECONFIG }} + HELM_REPO_TOKEN: ${{ secrets.PAT_TOKEN }} \ No newline at end of file From 78716303fbf5cfcc844bc5908440b5916c24921c Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:01:30 -0400 Subject: [PATCH 04/20] correct job name --- .github/workflows/ci-cd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index bbfa89d..1ced3d8 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -8,7 +8,7 @@ on: branches: [ main ] jobs: - call-reusable-workflow: + call-standard-dorkcer-workflow: uses: gbh-recruitment/ismael-ortiz-montero-ismaelortiz87-2025-5-29-senior-devops-challenge/.github/workflows/standard-docker-build-deploy.yml@main with: app_name: "api" From 1389e7860fb0568a276cccbfc88ef2ee789d99f5 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:26:44 -0400 Subject: [PATCH 05/20] change strategy to standalone cicd due to RBAC limitations --- .github/workflows/ci-cd.yaml | 131 +++++++++++++++++++++++++++++++---- 1 file changed, 118 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 1ced3d8..a5d7e47 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -1,3 +1,6 @@ +# .github/workflows/ci-cd.yml +# Place this file in the demo-api repository + name: Demo API CI/CD on: @@ -7,17 +10,119 @@ on: push: branches: [ main ] +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}/api + jobs: - call-standard-dorkcer-workflow: - uses: gbh-recruitment/ismael-ortiz-montero-ismaelortiz87-2025-5-29-senior-devops-challenge/.github/workflows/standard-docker-build-deploy.yml@main - with: - app_name: "api" - dockerfile_path: "Dockerfile" - helm_chart_repo: "gbh-recruitment/ismael-ortiz-montero-ismaelortiz87-2025-5-29-senior-devops-challenge" - helm_chart_path: "part_2/helm/generic-web-chart" - helm_release_name: "demo-api" - k8s_namespace: "gbh" - deploy_on_main: true - secrets: - KUBECONFIG: ${{ secrets.KUBECONFIG }} - HELM_REPO_TOKEN: ${{ secrets.PAT_TOKEN }} \ No newline at end of file + build: + name: Build API + runs-on: ubuntu-latest + outputs: + image-tag: ${{ steps.meta.outputs.tags }} + image-digest: ${{ steps.build.outputs.digest }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + deploy: + name: Deploy API + runs-on: ubuntu-latest + needs: build + # Only deploy on push to main branch + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + + steps: + - name: Set up kubectl + uses: azure/setup-kubectl@v3 + with: + version: 'v1.28.0' + + - name: Set up Helm + uses: azure/setup-helm@v3 + with: + version: '3.12.0' + + - name: Configure kubectl + run: | + mkdir -p $HOME/.kube + echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config + chmod 600 $HOME/.kube/config + + - name: Verify cluster connection + run: | + kubectl cluster-info + kubectl get nodes + + - name: Checkout Helm chart repository + uses: actions/checkout@v4 + with: + repository: gbh-recruitment/ismael-ortiz-montero-ismaelortiz87-2025-5-29-senior-devops-challenge + token: ${{ secrets.PAT_TOKEN }} + path: helm-repo + + - name: Verify Helm chart exists + run: | + echo "Checking for Helm chart at: ./helm-repo/part_2/helm/generic-web-chart" + ls -la ./helm-repo/part_2/helm/generic-web-chart/ + + if [ ! -f "./helm-repo/part_2/helm/generic-web-chart/Chart.yaml" ]; then + echo "ERROR: Chart.yaml not found at ./helm-repo/part_2/helm/generic-web-chart/" + exit 1 + fi + + echo "Chart.yaml found, proceeding with deployment" + + - name: Deploy API with Helm + run: | + # Extract image information + IMAGE_TAG="${{ needs.build.outputs.image-tag }}" + FULL_IMAGE=$(echo $IMAGE_TAG | cut -d',' -f1) + IMAGE_REPO=$(echo $FULL_IMAGE | cut -d':' -f1) + IMAGE_VERSION=$(echo $FULL_IMAGE | cut -d':' -f2) + + echo "Deploying API with image: $FULL_IMAGE" + + # Deploy using Helm + helm upgrade --install demo-api ./helm-repo/part_2/helm/generic-web-chart \ + --namespace gbh \ + --create-namespace \ + --set api.image.repository=$IMAGE_REPO \ + --set api.image.tag=$IMAGE_VERSION \ + --set api.image.pullPolicy=Always \ + --timeout=10m \ + --wait \ No newline at end of file From 464b21fd8a9df1a146af95687307abf99d09eded Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:27:13 -0400 Subject: [PATCH 06/20] modify triggers --- .github/workflows/ci-cd.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index a5d7e47..992b468 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -7,8 +7,8 @@ on: workflow_dispatch: pull_request: branches: [ main, develop ] - push: - branches: [ main ] + # push: + # branches: [ main ] env: REGISTRY: ghcr.io From 50144caf7517cd652ef7f68e2efc0d6475ea4d8e Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:35:00 -0400 Subject: [PATCH 07/20] fix image tag issues --- .github/workflows/ci-cd.yaml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 992b468..bfd92bd 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -7,12 +7,12 @@ on: workflow_dispatch: pull_request: branches: [ main, develop ] - # push: - # branches: [ main ] + push: + branches: [ main ] env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}/api + REGISTRY: justranacr.azurecr.io + IMAGE_NAME: ${{ github.repository }} jobs: build: @@ -30,8 +30,8 @@ jobs: uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + username: justranacr + password: ${{ secrets.ACR_PASSWORD }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -42,9 +42,7 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=ref,event=branch - type=ref,event=pr - type=sha,prefix={{branch}}- + type=raw,value=${{ github.run_number }} type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Docker image From 8428125e9d785b063cb12b68dcbd32c368f32ff6 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:35:25 -0400 Subject: [PATCH 08/20] minimal fix --- .github/workflows/ci-cd.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index bfd92bd..20b6346 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -1,6 +1,3 @@ -# .github/workflows/ci-cd.yml -# Place this file in the demo-api repository - name: Demo API CI/CD on: From 0fa0c2de4b275dfb40e52a741114235c0f62b12a Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:41:13 -0400 Subject: [PATCH 09/20] minimal fix --- .github/workflows/ci-cd.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 20b6346..e8225e7 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -58,8 +58,8 @@ jobs: name: Deploy API runs-on: ubuntu-latest needs: build - # Only deploy on push to main branch - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + # Deploy on push to main branch OR manual trigger + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' steps: - name: Set up kubectl From 83da79ee309bbd1fa769e5db6fdb594fdf26c768 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:44:47 -0400 Subject: [PATCH 10/20] debug deploy stage --- .github/workflows/ci-cd.yaml | 76 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index e8225e7..4264dbb 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -12,52 +12,52 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build: - name: Build API - runs-on: ubuntu-latest - outputs: - image-tag: ${{ steps.meta.outputs.tags }} - image-digest: ${{ steps.build.outputs.digest }} + # build: + # name: Build API + # runs-on: ubuntu-latest + # outputs: + # image-tag: ${{ steps.meta.outputs.tags }} + # image-digest: ${{ steps.build.outputs.digest }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 - - name: Log in to Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: justranacr - password: ${{ secrets.ACR_PASSWORD }} + # - name: Log in to Container Registry + # uses: docker/login-action@v3 + # with: + # registry: ${{ env.REGISTRY }} + # username: justranacr + # password: ${{ secrets.ACR_PASSWORD }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v3 - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=raw,value=${{ github.run_number }} - type=raw,value=latest,enable={{is_default_branch}} + # - name: Extract metadata + # id: meta + # uses: docker/metadata-action@v5 + # with: + # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # tags: | + # type=raw,value=${{ github.run_number }} + # type=raw,value=latest,enable={{is_default_branch}} - - name: Build and push Docker image - id: build - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + # - name: Build and push Docker image + # id: build + # uses: docker/build-push-action@v5 + # with: + # context: . + # file: ./Dockerfile + # push: true + # tags: ${{ steps.meta.outputs.tags }} + # labels: ${{ steps.meta.outputs.labels }} + # cache-from: type=gha + # cache-to: type=gha,mode=max deploy: name: Deploy API runs-on: ubuntu-latest - needs: build + # needs: build # Deploy on push to main branch OR manual trigger if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' @@ -75,7 +75,7 @@ jobs: - name: Configure kubectl run: | mkdir -p $HOME/.kube - echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config + echo "${{ secrets.KUBECONFIG }}" | $HOME/.kube/config chmod 600 $HOME/.kube/config - name: Verify cluster connection From b6ee48c5558a1e181732f2bd727d3e23c28c2fc2 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:45:33 -0400 Subject: [PATCH 11/20] minimal fix --- .github/workflows/ci-cd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 4264dbb..415af41 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -75,7 +75,7 @@ jobs: - name: Configure kubectl run: | mkdir -p $HOME/.kube - echo "${{ secrets.KUBECONFIG }}" | $HOME/.kube/config + echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config chmod 600 $HOME/.kube/config - name: Verify cluster connection From 61d203007d79e66681667a3096d0aae58bf60a79 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 20:52:06 -0400 Subject: [PATCH 12/20] minimal fix --- .github/workflows/ci-cd.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 415af41..d69cc43 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -114,6 +114,7 @@ jobs: # Deploy using Helm helm upgrade --install demo-api ./helm-repo/part_2/helm/generic-web-chart \ + -f ./helm-repo/part_2/helm/generic-web-chart/values-api.yaml \ --namespace gbh \ --create-namespace \ --set api.image.repository=$IMAGE_REPO \ From bac4a300cc8503f5b94b4ba70b0c8d1a5b9d55ec Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 21:15:58 -0400 Subject: [PATCH 13/20] cleanup --- .github/workflows/ci-cd.yaml | 82 +++++++++++++++--------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index d69cc43..25febc7 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -12,46 +12,46 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - # build: - # name: Build API - # runs-on: ubuntu-latest - # outputs: - # image-tag: ${{ steps.meta.outputs.tags }} - # image-digest: ${{ steps.build.outputs.digest }} + build: + name: Build API + runs-on: ubuntu-latest + outputs: + image-tag: ${{ steps.meta.outputs.tags }} + image-digest: ${{ steps.build.outputs.digest }} - # steps: - # - name: Checkout repository - # uses: actions/checkout@v4 + steps: + - name: Checkout repository + uses: actions/checkout@v4 - # - name: Log in to Container Registry - # uses: docker/login-action@v3 - # with: - # registry: ${{ env.REGISTRY }} - # username: justranacr - # password: ${{ secrets.ACR_PASSWORD }} + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: justranacr + password: ${{ secrets.ACR_PASSWORD }} - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - # - name: Extract metadata - # id: meta - # uses: docker/metadata-action@v5 - # with: - # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # tags: | - # type=raw,value=${{ github.run_number }} - # type=raw,value=latest,enable={{is_default_branch}} + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ github.run_number }} + type=raw,value=latest,enable={{is_default_branch}} - # - name: Build and push Docker image - # id: build - # uses: docker/build-push-action@v5 - # with: - # context: . - # file: ./Dockerfile - # push: true - # tags: ${{ steps.meta.outputs.tags }} - # labels: ${{ steps.meta.outputs.labels }} - # cache-from: type=gha + - name: Build and push Docker image + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha # cache-to: type=gha,mode=max deploy: @@ -90,18 +90,6 @@ jobs: token: ${{ secrets.PAT_TOKEN }} path: helm-repo - - name: Verify Helm chart exists - run: | - echo "Checking for Helm chart at: ./helm-repo/part_2/helm/generic-web-chart" - ls -la ./helm-repo/part_2/helm/generic-web-chart/ - - if [ ! -f "./helm-repo/part_2/helm/generic-web-chart/Chart.yaml" ]; then - echo "ERROR: Chart.yaml not found at ./helm-repo/part_2/helm/generic-web-chart/" - exit 1 - fi - - echo "Chart.yaml found, proceeding with deployment" - - name: Deploy API with Helm run: | # Extract image information From 79bd3c3423f2eb95040cde1d70d22901410ef54c Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 21:23:53 -0400 Subject: [PATCH 14/20] fix helm values --- .github/workflows/ci-cd.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 25febc7..a99a83b 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -105,8 +105,8 @@ jobs: -f ./helm-repo/part_2/helm/generic-web-chart/values-api.yaml \ --namespace gbh \ --create-namespace \ - --set api.image.repository=$IMAGE_REPO \ - --set api.image.tag=$IMAGE_VERSION \ - --set api.image.pullPolicy=Always \ + --set image.repository=$IMAGE_REPO \ + --set image.tag=$IMAGE_VERSION \ + --set image.pullPolicy=Always \ --timeout=10m \ --wait \ No newline at end of file From 1c0d3914b90a8bc5175e1404da8aa16a3961a5d1 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 21:30:59 -0400 Subject: [PATCH 15/20] rollback faulty change --- .github/workflows/ci-cd.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index a99a83b..25febc7 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -105,8 +105,8 @@ jobs: -f ./helm-repo/part_2/helm/generic-web-chart/values-api.yaml \ --namespace gbh \ --create-namespace \ - --set image.repository=$IMAGE_REPO \ - --set image.tag=$IMAGE_VERSION \ - --set image.pullPolicy=Always \ + --set api.image.repository=$IMAGE_REPO \ + --set api.image.tag=$IMAGE_VERSION \ + --set api.image.pullPolicy=Always \ --timeout=10m \ --wait \ No newline at end of file From 310cfb35c03ce1fee4884202c914032cc092b15a Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 21:54:36 -0400 Subject: [PATCH 16/20] fix dependencies --- .github/workflows/ci-cd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 25febc7..573e234 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -57,7 +57,7 @@ jobs: deploy: name: Deploy API runs-on: ubuntu-latest - # needs: build + needs: build # Deploy on push to main branch OR manual trigger if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' From 409369165b2dff297d72b258b9f53f0db5c2d38e Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 22:29:01 -0400 Subject: [PATCH 17/20] importing fixes --- .github/workflows/ci-cd.yaml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 573e234..f1df8a4 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -92,21 +92,24 @@ jobs: - name: Deploy API with Helm run: | - # Extract image information - IMAGE_TAG="${{ needs.build.outputs.image-tag }}" - FULL_IMAGE=$(echo $IMAGE_TAG | cut -d',' -f1) - IMAGE_REPO=$(echo $FULL_IMAGE | cut -d':' -f1) - IMAGE_VERSION=$(echo $FULL_IMAGE | cut -d':' -f2) + IMAGE_REPO=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + IMAGE_VERSION=${{ github.run_number }} + FULL_IMAGE=$IMAGE_REPO:$IMAGE_VERSION + + echo "Deploying WebApp with image: $FULL_IMAGE" + echo "Image Repository: $IMAGE_REPO" + echo "Image Tag: $IMAGE_VERSION" echo "Deploying API with image: $FULL_IMAGE" # Deploy using Helm helm upgrade --install demo-api ./helm-repo/part_2/helm/generic-web-chart \ - -f ./helm-repo/part_2/helm/generic-web-chart/values-api.yaml \ --namespace gbh \ - --create-namespace \ - --set api.image.repository=$IMAGE_REPO \ - --set api.image.tag=$IMAGE_VERSION \ - --set api.image.pullPolicy=Always \ + -- values ./helm-repo/part_2/helm/generic-web-chart/values-api.yaml \ + --set fullnameOverride=api \ + --set image.repository="$IMAGE_REPO" \ + --set image.tag="$IMAGE_VERSION" \ + --set image.pullPolicy=Always \ + --set env.REACT_APP_API_URL="$REACT_APP_API_URL" \ --timeout=10m \ --wait \ No newline at end of file From b2e759887946057e751f9539db681480cd273690 Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 22:33:08 -0400 Subject: [PATCH 18/20] fix --- .github/workflows/ci-cd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index f1df8a4..48a4f7e 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -105,7 +105,7 @@ jobs: # Deploy using Helm helm upgrade --install demo-api ./helm-repo/part_2/helm/generic-web-chart \ --namespace gbh \ - -- values ./helm-repo/part_2/helm/generic-web-chart/values-api.yaml \ + --values ./helm-repo/part_2/helm/generic-web-chart/values-api.yaml \ --set fullnameOverride=api \ --set image.repository="$IMAGE_REPO" \ --set image.tag="$IMAGE_VERSION" \ From 9a3fcccd83c176fc897fc00b6cced92f1c5b08ad Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 22:43:26 -0400 Subject: [PATCH 19/20] fix port issue --- app.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 1ef49dc..563b941 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ import cors from 'cors'; -import dotenv from "dotenv" +import dotenv from "dotenv"; import express from 'express'; import parser from 'body-parser'; import apiRouter from './src/routes/api.js'; @@ -19,10 +19,11 @@ app.use(parser.json()); app.use('/', apiRouter); /* Initialize the API server */ -const port = process.env.API_PORT || 3001; +const port = process.env.port || process.env.API_port || 3001; +const host = process.env.host || '0.0.0.0'; -app.listen( port, () => { - console.log(`Server running on: ${port}.`) +app.listen(port, host, () => { + console.log(`Server running on: ${port}.`); }); -export default app; +export default app; \ No newline at end of file From 25c84fbe73de25d57caa8cf87906b80f182d898f Mon Sep 17 00:00:00 2001 From: ismaelortiz87 Date: Sun, 1 Jun 2025 23:19:48 -0400 Subject: [PATCH 20/20] add seccondary registry --- .github/workflows/ci-cd.yaml | 72 ++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 48a4f7e..7b029d9 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -15,44 +15,54 @@ jobs: build: name: Build API runs-on: ubuntu-latest + permissions: + contents: read + packages: write outputs: image-tag: ${{ steps.meta.outputs.tags }} image-digest: ${{ steps.build.outputs.digest }} - + steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Log in to Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: justranacr - password: ${{ secrets.ACR_PASSWORD }} + - name: Login to ACR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: justranacr + password: ${{ secrets.ACR_PASSWORD }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=raw,value=${{ github.run_number }} - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push Docker image - id: build - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - # cache-to: type=gha,mode=max + - uses: docker/setup-buildx-action@v3 + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ github.run_number }} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build & push image + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max deploy: name: Deploy API