Difference between revisions of "My-docker-publish.yml"

From wikieduonline
Jump to navigation Jump to search
Line 91: Line 91:
  
 
== Related ==
 
== Related ==
* [[docker-publish.yml]]
+
* <code>[[docker-publish.yml]]</code>
  
 +
== See also ==
 +
* {{GitHub Actions}}
  
{{GitHub Actions}}
+
[[Category:GitHub]]

Revision as of 02:25, 17 June 2024

name: Build & deploy xxxxx container to stage env
on: workflow_dispatch 

env:
  ACTIONS_RUNNER_DEBUG: true
  #AWS_REGION: MY_AWS_REGION                  
  ECR_REPOSITORY: your-repo          
  ECR_REGISTRY: 12312432424234.dkr.ecr.eu-west-1.amazonaws.com
  #ECS_SERVICE: MY_ECS_SERVICE                
  #ECS_CLUSTER: MY_ECS_CLUSTER               
  #ECS_TASK_DEFINITION: MY_ECS_TASK_DEFINITION                                               
  CONTAINER_NAME: your-container-name      
        
jobs:
  build-docker-image:
    runs-on: self-hosted
    environment: build
    permissions:
      id-token: write
      contents: read

   steps:
     - name: Checkout
       uses: actions/checkout@v3
     - name: Configure AWS Credentials
       uses: actions/configure-aws-credentials@v2.0.0
       with:
         aws-region: eu-west-1
     - name: Login to Private ECR
       id: login-private-ecr
       uses: actions/amazon-ecr-login@v2.0.0
       
     - name: Build, tag, and push image to Amazon ECR
       id: build-image
       env:
         #ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
         #IMAGE_TAG: ${{ github.sha }}
         IMAGE_TAG: latest
       working-directory: ./your-working-dir
       run: |
         # Build a docker container and
         # push it to ECR so that it can
         # be deployed to ECS.
         echo "DEBUG: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
         docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
         
         echo "============ BEGIN DEBUG ================"
         aws ecr describe-repositories | grep repositoryName
         echo "============ END DEBUG ================"
         
         docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
         echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
              
 deploy-docker-image:
   runs-on: self-hosted
   environment: deploy
   needs: build-docker-image
   permissions:
     id-token: write
     contents: read
   steps:
     - name: Checkout
       uses: actions/checkout@v3
     - name: Configure AWS Credentials
       uses: actions/[email protected]
       with:
         aws-region: eu-west-1
     - name: Login to Private ECR
       id: login-private-ecr
       uses: actions/[email protected]
       
     - name: Configure AWS credentials
       uses: aws-actions/configure-aws-credentials@v1
       with:
         aws-access-key-id: ${{ secrets.STAGING_DEPLOY_ACCESS_KEY }}
         aws-secret-access-key: ${{ secrets.STAGING_DEPLOY_ACCESS_SECRET }}
         aws-region: eu-west-1
     - name: Force ECS deployment
       run: |
          aws ecs update-service --cluster your-cluster-name --service your-service --force-new-deployment


Related

See also

Advertising: