diff --git a/.github/workflows/deploy_production.yml b/.github/workflows/deploy_production.yml index b8c5debce..b7f58eb99 100644 --- a/.github/workflows/deploy_production.yml +++ b/.github/workflows/deploy_production.yml @@ -13,6 +13,7 @@ permissions: env: AWS_DEFAULT_REGION: us-east-1 LOCAL_TAG_NAME: research-catalog:${{ github.ref_name }}-${{ github.run_number }} + APP_ENV: production jobs: deploy: @@ -33,13 +34,15 @@ jobs: - name: Build and push Docker image to Amazon ECR env: - NEXT_PUBLIC_APP_ENV: production - ECR_URL: 946183545209.dkr.ecr.us-east-1.amazonaws.com/research-catalog:production-latest + ECR_URL: 946183545209.dkr.ecr.us-east-1.amazonaws.com/research-catalog:$APP_ENV-latest + MANIFEST: $(aws ecr batch-get-image --repository-name research-catalog --image-ids imageTag="$APP_ENV-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') run: | - docker build --build-arg NEXT_PUBLIC_APP_ENV=$NEXT_PUBLIC_APP_ENV --tag $LOCAL_TAG_NAME . + docker build --build-arg NEXT_PUBLIC_APP_ENV=$APP_ENV --tag $LOCAL_TAG_NAME . docker tag $LOCAL_TAG_NAME $ECR_URL + aws ecr batch-delete-image --repository-name research-catalog --image-ids imageTag="$APP_ENV-previous" || true + aws ecr put-image --repository-name research-catalog --image-tag "$APP_ENV-previous" --image-manifest "$MANIFEST" || true docker push $ECR_URL - name: Update ECS service run: | - aws ecs update-service --cluster research-catalog-production --service research-catalog-production --force-new-deployment + aws ecs update-service --cluster research-catalog-$APP_ENV --service research-catalog-$APP_ENV --force-new-deployment diff --git a/.github/workflows/deploy_qa.yml b/.github/workflows/deploy_qa.yml index 63e43c067..92f815924 100644 --- a/.github/workflows/deploy_qa.yml +++ b/.github/workflows/deploy_qa.yml @@ -14,6 +14,7 @@ permissions: env: AWS_DEFAULT_REGION: us-east-1 LOCAL_TAG_NAME: research-catalog:${{ github.ref_name }}-${{ github.run_number }} + APP_ENV: qa jobs: deploy: @@ -34,13 +35,16 @@ jobs: - name: Build and push Docker image to Amazon ECR env: - NEXT_PUBLIC_APP_ENV: qa - ECR_URL: 946183545209.dkr.ecr.us-east-1.amazonaws.com/research-catalog:$NEXT_PUBLIC_APP_ENV-latest + ECR_URL: 946183545209.dkr.ecr.us-east-1.amazonaws.com/research-catalog:$APP_ENV-latest + MANIFEST: $(aws ecr batch-get-image --repository-name research-catalog --image-ids imageTag="$APP_ENV-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') + run: | - docker build --build-arg NEXT_PUBLIC_APP_ENV=$NEXT_PUBLIC_APP_ENV --tag $LOCAL_TAG_NAME . + docker build --build-arg NEXT_PUBLIC_APP_ENV=$APP_ENV --tag $LOCAL_TAG_NAME . docker tag $LOCAL_TAG_NAME $ECR_URL + aws ecr batch-delete-image --repository-name research-catalog --image-ids imageTag="$APP_ENV-previous" || true + aws ecr put-image --repository-name research-catalog --image-tag "$APP_ENV-previous" --image-manifest "$MANIFEST" || true # docker push $ECR_URL # - name: Update ECS service # run: | - # aws ecs update-service --cluster research-catalog-qa --service research-catalog-qa --force-new-deployment + # aws ecs update-service --cluster research-catalog-$APP_ENV --service research-catalog-$APP_ENV --force-new-deployment