mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 05:45:50 +00:00
Add ECR repository name output for debugging
This commit is contained in:
parent
dbd3abc82a
commit
6cd96461a0
1 changed files with 29 additions and 8 deletions
33
.github/workflows/deploy.yml
vendored
33
.github/workflows/deploy.yml
vendored
|
@ -17,43 +17,54 @@
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- dev
|
- dev
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy-infrastructure:
|
deploy-infrastructure:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: ${{ github.event.inputs.environment }}
|
environment: ${{ github.event.inputs.environment }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set environment name
|
||||||
|
run: echo "ENV_NAME=${{ github.event.inputs.environment || 'dev' }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
aws-region: us-west-2
|
aws-region: us-west-2
|
||||||
|
|
||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
uses: hashicorp/setup-terraform@v2
|
uses: hashicorp/setup-terraform@v2
|
||||||
|
|
||||||
- name: Terraform Init
|
- name: Terraform Init
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
run: terraform init
|
run: terraform init
|
||||||
|
|
||||||
- name: Terraform Plan
|
- name: Terraform Plan
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
run: |
|
run: |
|
||||||
terraform plan -var="environment=${{ github.event.inputs.environment }}" \
|
echo "Using environment: ${{ env.ENV_NAME }}"
|
||||||
|
terraform plan -var="environment=${{ env.ENV_NAME }}" \
|
||||||
-var="db_username=${{ secrets.DB_USERNAME }}" \
|
-var="db_username=${{ secrets.DB_USERNAME }}" \
|
||||||
-var="db_password=${{ secrets.DB_PASSWORD }}" \
|
-var="db_password=${{ secrets.DB_PASSWORD }}" \
|
||||||
-var="vpc_id=${{ secrets.VPC_ID }}"
|
-var="vpc_id=${{ secrets.VPC_ID }}"
|
||||||
|
|
||||||
- name: Terraform Apply
|
- name: Terraform Apply
|
||||||
if: github.event.inputs.environment != 'prod'
|
if: github.event.inputs.environment != 'prod'
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
run: |
|
run: |
|
||||||
terraform apply -auto-approve -var="environment=${{ github.event.inputs.environment }}" \
|
terraform apply -auto-approve -var="environment=${{ env.ENV_NAME }}" \
|
||||||
-var="db_username=${{ secrets.DB_USERNAME }}" \
|
-var="db_username=${{ secrets.DB_USERNAME }}" \
|
||||||
-var="db_password=${{ secrets.DB_PASSWORD }}" \
|
-var="db_password=${{ secrets.DB_PASSWORD }}" \
|
||||||
-var="vpc_id=${{ secrets.VPC_ID }}"
|
-var="vpc_id=${{ secrets.VPC_ID }}"
|
||||||
|
|
||||||
- name: Terraform Apply (Production)
|
- name: Terraform Apply (Production)
|
||||||
if: github.event.inputs.environment == 'prod'
|
if: github.event.inputs.environment == 'prod'
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
run: |
|
run: |
|
||||||
terraform apply -var="environment=${{ github.event.inputs.environment }}" \
|
terraform apply -var="environment=${{ env.ENV_NAME }}" \
|
||||||
-var="db_username=${{ secrets.DB_USERNAME }}" \
|
-var="db_username=${{ secrets.DB_USERNAME }}" \
|
||||||
-var="db_password=${{ secrets.DB_PASSWORD }}" \
|
-var="db_password=${{ secrets.DB_PASSWORD }}" \
|
||||||
-var="vpc_id=${{ secrets.VPC_ID }}"
|
-var="vpc_id=${{ secrets.VPC_ID }}"
|
||||||
|
@ -64,38 +75,48 @@
|
||||||
environment: ${{ github.event.inputs.environment }}
|
environment: ${{ github.event.inputs.environment }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set environment name
|
||||||
|
run: echo "ENV_NAME=${{ github.event.inputs.environment || 'dev' }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
cache: maven
|
cache: maven
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
aws-region: us-west-2
|
aws-region: us-west-2
|
||||||
|
|
||||||
- name: Login to Amazon ECR
|
- name: Login to Amazon ECR
|
||||||
id: login-ecr
|
id: login-ecr
|
||||||
uses: aws-actions/amazon-ecr-login@v1
|
uses: aws-actions/amazon-ecr-login@v1
|
||||||
|
|
||||||
- name: Build, tag, and push image to Amazon ECR
|
- name: Build, tag, and push image to Amazon ECR
|
||||||
env:
|
env:
|
||||||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
||||||
ECR_REPOSITORY: petclinic-${{ github.event.inputs.environment }}
|
ECR_REPOSITORY: petclinic-${{ env.ENV_NAME }}
|
||||||
IMAGE_TAG: ${{ github.sha }}
|
IMAGE_TAG: ${{ github.sha }}
|
||||||
run: |
|
run: |
|
||||||
|
echo "Using environment: ${{ env.ENV_NAME }}"
|
||||||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
|
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
|
||||||
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
||||||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
||||||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
||||||
|
|
||||||
- name: Deploy to ECS
|
- name: Deploy to ECS
|
||||||
run: |
|
run: |
|
||||||
aws ecs update-service --cluster petclinic-${{ github.event.inputs.environment }} \
|
aws ecs update-service --cluster petclinic-${{ env.ENV_NAME }} \
|
||||||
--service petclinic-service \
|
--service petclinic-service \
|
||||||
--force-new-deployment
|
--force-new-deployment
|
||||||
|
|
||||||
- name: Verify Deployment
|
- name: Verify Deployment
|
||||||
run: |
|
run: |
|
||||||
echo "Waiting for deployment to complete..."
|
echo "Waiting for deployment to complete..."
|
||||||
aws ecs wait services-stable --cluster petclinic-${{ github.event.inputs.environment }} \
|
aws ecs wait services-stable --cluster petclinic-${{ env.ENV_NAME }} \
|
||||||
--services petclinic-service
|
--services petclinic-service
|
Loading…
Reference in a new issue