|
| 1 | +name: Build and Deploy Prometheus |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: main |
| 6 | + |
| 7 | +env: |
| 8 | + AWS_REGION: ap-northeast-2 |
| 9 | + ECR_REPOSITORY: beforegoing-prometheus |
| 10 | + S3_BUCKET_NAME: codedeploy-artifact-prometheus-beforegoingdapne2 |
| 11 | + APPLICATION_NAME: codedeploy-app-prometheus-beforegoingdapne2 |
| 12 | + DEPLOYMENT_GROUP_NAME: codedeploy-group-prometheus-beforegoingdapne2 |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-deploy: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + working-directory: prometheus |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Configure AWS credentials |
| 29 | + uses: aws-actions/configure-aws-credentials@v4 |
| 30 | + with: |
| 31 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 32 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 33 | + aws-region: ${{ env.AWS_REGION }} |
| 34 | + |
| 35 | + - name: Login to Amazon ECR |
| 36 | + id: login-ecr |
| 37 | + uses: aws-actions/amazon-ecr-login@v2 |
| 38 | + |
| 39 | + - name: Build, tag, and push image to Amazon ECR |
| 40 | + env: |
| 41 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 42 | + IMAGE_TAG: ${{ github.sha }} |
| 43 | + run: | |
| 44 | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . |
| 45 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 46 | + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest |
| 47 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest |
| 48 | +
|
| 49 | + - name: Create deployment package |
| 50 | + run: | |
| 51 | + zip -r ../deployment-${{ github.sha }}.zip . |
| 52 | +
|
| 53 | + - name: Upload deployment package to S3 |
| 54 | + run: | |
| 55 | + aws s3 cp ../deployment-${{ github.sha }}.zip s3://$S3_BUCKET_NAME/deployment-${{ github.sha }}.zip |
| 56 | +
|
| 57 | + - name: Create CodeDeploy deployment |
| 58 | + run: | |
| 59 | + aws deploy create-deployment \ |
| 60 | + --application-name $APPLICATION_NAME \ |
| 61 | + --deployment-group-name $DEPLOYMENT_GROUP_NAME \ |
| 62 | + --description "Deployment from GitHub Actions - commit ${{ github.sha }}" \ |
| 63 | + --s3-location bucket=$S3_BUCKET_NAME,key=deployment-${{ github.sha }}.zip,bundleType=zip |
0 commit comments