mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:25:50 +00:00
Update ci-cd.yml [skip ci]
Using dockerhub instead of ECR due to LabRole restrictions
This commit is contained in:
parent
f3efa01ef4
commit
1dab2b7f8f
1 changed files with 16 additions and 49 deletions
65
.github/workflows/ci-cd.yml
vendored
65
.github/workflows/ci-cd.yml
vendored
|
@ -7,37 +7,13 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
sonarcloud:
|
||||||
runs-on: ubuntu-latest
|
uses: ./.github/workflows/sonarcloud.yml
|
||||||
steps:
|
secrets:
|
||||||
- name: Checkout code
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up JDK 17
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
java-version: '17'
|
|
||||||
distribution: 'temurin'
|
|
||||||
|
|
||||||
- name: Run Tests with Coverage
|
|
||||||
run: ./mvnw test jacoco:report
|
|
||||||
|
|
||||||
- name: SonarCloud Scan
|
|
||||||
uses: SonarSource/sonarcloud-github-action@master
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
||||||
|
|
||||||
- name: Upload Coverage Reports
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: coverage-reports
|
|
||||||
path: target/site/jacoco/*.xml
|
|
||||||
|
|
||||||
build-and-push:
|
build-and-push:
|
||||||
needs: test
|
needs: sonarcloud
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
|
@ -50,23 +26,16 @@ jobs:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
|
|
||||||
- name: Build Image with Maven
|
- name: Build Image with Maven
|
||||||
run: ./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=mtu/petclinic:${{ github.sha }} --no-transfer-progress
|
run: ./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=${{ secrets.DOCKERHUB_USERNAME }}/petclinic:${{ github.sha }} --no-transfer-progress
|
||||||
|
|
||||||
- name: Configure AWS Credentials
|
- name: Log in to Docker Hub
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
aws-region: us-east-1
|
|
||||||
|
|
||||||
- name: Login to Amazon ECR
|
- name: Push Image to Docker Hub
|
||||||
run: aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 215262883158.dkr.ecr.us-east-1.amazonaws.com
|
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/petclinic:${{ github.sha }}
|
||||||
|
|
||||||
- name: Tag Image
|
|
||||||
run: docker tag mtu/petclinic:${{ github.sha }} 215262883158.dkr.ecr.us-east-1.amazonaws.com/mtu/petclinic:${{ github.sha }}
|
|
||||||
|
|
||||||
- name: Push Image to ECR
|
|
||||||
run: docker push 215262883158.dkr.ecr.us-east-1.amazonaws.com/mtu/petclinic:${{ github.sha }}
|
|
||||||
|
|
||||||
deploy-staging:
|
deploy-staging:
|
||||||
needs: build-and-push
|
needs: build-and-push
|
||||||
|
@ -79,8 +48,7 @@ jobs:
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: aws-actions/configure-aws-credentials@v4
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/LabRole
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
||||||
aws-region: us-east-1
|
aws-region: us-east-1
|
||||||
|
|
||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
|
@ -93,7 +61,7 @@ jobs:
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
|
|
||||||
- name: Terraform Apply Staging
|
- name: Terraform Apply Staging
|
||||||
run: terraform apply -auto-approve -var "image_tag=${{ github.sha }}" -var "environment=staging"
|
run: terraform apply -auto-approve -var "image_tag=${{ github.sha }}" -var "environment=staging" -var "dockerhub_username=${{ secrets.DOCKERHUB_USERNAME }}"
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
|
|
||||||
- name: Send Slack Notification (Staging)
|
- name: Send Slack Notification (Staging)
|
||||||
|
@ -121,8 +89,7 @@ jobs:
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: aws-actions/configure-aws-credentials@v4
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/LabRole
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
||||||
aws-region: us-east-1
|
aws-region: us-east-1
|
||||||
|
|
||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
|
@ -135,7 +102,7 @@ jobs:
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
|
|
||||||
- name: Terraform Apply Production
|
- name: Terraform Apply Production
|
||||||
run: terraform apply -auto-approve -var "image_tag=${{ github.sha }}" -var "environment=production"
|
run: terraform apply -auto-approve -var "image_tag=${{ github.sha }}" -var "environment=production" -var "dockerhub_username=${{ secrets.DOCKERHUB_USERNAME }}"
|
||||||
working-directory: ./terraform
|
working-directory: ./terraform
|
||||||
|
|
||||||
- name: Send Slack Notification (Production)
|
- name: Send Slack Notification (Production)
|
||||||
|
|
Loading…
Reference in a new issue