Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.9 kB
1
Indexable
Never
name: Deploy Needy New

on:
  workflow_dispatch:
    inputs:
      environment:
        type: choice
        description: Choose the environment to deploy to
        options:
          - stage
          - prod
          - both
        default: stage
  push:
    branches:
      - terraform


permissions:
  id-token: write
  contents: read

env:
  STAGE_CLUSTER_NAME: staging
  PROD_CLUSTER_NAME: production
  AWS_DEFAULT_REGION: us-east-1
  PROD_PROJECT_NAME: needy-prod
  PROD_VALUES_FILE: prod_values.yaml
  STAGE_PROJECT_NAME: needy-stage
  STAGE_VALUES_FILE: stage_values.yaml

jobs:
  build:
    name: Build Image
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@v2

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v3
        with:
          role-to-assume: arn:aws:iam::767397862679:role/GithubActionRole
          role-session-name: GitHub_to_AWS_via_FederatedOIDC
          aws-region: us-east-1

      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@master

      - name: Docker cache layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-single-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-single-buildx

      - name: Set release version
        run: echo "RELEASE_REVISION=$(date +'%s')" >> $GITHUB_ENV


      - name: Build & Push Image
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
          MICROSERVICE_RELEASE_IMAGE: ${{ steps.login-ecr.outputs.registry }}/microservice:${{ env.RELEASE_REVISION }}
          WEBAPP_RELEASE_IMAGE: ${{ steps.login-ecr.outputs.registry }}/webapp:${{ env.RELEASE_REVISION }}
        run: |

          echo "microservice image: ${{ env.MICROSERVICE_RELEASE_IMAGE }}"
          docker buildx create --use

          docker buildx build \
            --platform linux/amd64 \
            --tag ${{ env.MICROSERVICE_RELEASE_IMAGE }} \
            --file ./src/needy/services/Dockerfile \
            --cache-from=type=local,src=/tmp/.buildx-cache \
            --cache-to=type=local,dest=/tmp/.buildx-cache-new \
            . --push

          docker buildx build \
            --platform linux/amd64 \
            --tag ${{ env.WEBAPP_RELEASE_IMAGE }} \
            --file ./services/webapp/Dockerfile \
            --cache-from=type=local,src=/tmp/.buildx-cache \
            --cache-to=type=local,dest=/tmp/.buildx-cache-new \
            . --push

          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache

      - name: kubeconfig
        run: |
          aws eks update-kubeconfig --name ${{ env.STAGE_CLUSTER_NAME }} --region ${{ env.AWS_DEFAULT_REGION }} 
Leave a Comment