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

From wikieduonline
Jump to navigation Jump to search
 
(11 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
  name: Build & deploy xxxxx container to stage env
 
  name: Build & deploy xxxxx container to stage env
 
 
  [[on: workflow_dispatch]]  
 
  [[on: workflow_dispatch]]  
 
   
 
   
 
  [[env:]]
 
  [[env:]]
 
   ACTIONS_RUNNER_DEBUG: true
 
   ACTIONS_RUNNER_DEBUG: true
   #AWS_REGION: MY_AWS_REGION                   # set this to your preferred AWS region, e.g. us-west-1
+
   #AWS_REGION: MY_AWS_REGION                
   ECR_REPOSITORY: your-repo          # set this to your Amazon ECR repository name
+
   ECR_REPOSITORY: your-repo           
 
   ECR_REGISTRY: 12312432424234.dkr.ecr.eu-west-1.amazonaws.com
 
   ECR_REGISTRY: 12312432424234.dkr.ecr.eu-west-1.amazonaws.com
   #ECS_SERVICE: MY_ECS_SERVICE                 # set this to your Amazon ECS service name
+
   #ECS_SERVICE: MY_ECS_SERVICE              
   #ECS_CLUSTER: MY_ECS_CLUSTER                 # set this to your Amazon ECS cluster name
+
   #ECS_CLUSTER: MY_ECS_CLUSTER              
   #ECS_TASK_DEFINITION: MY_ECS_TASK_DEFINITION # set this to the path to your Amazon ECS task definition
+
   #ECS_TASK_DEFINITION: MY_ECS_TASK_DEFINITION                                              
                                                # file, e.g. .aws/task-definition.json
+
   CONTAINER_NAME: your-container-name    
   CONTAINER_NAME: your-container-name         # set this to the name of the container in the
+
       
                                              # containerDefinitions section of your task definition
+
  [[GitHub Actions: jobs:|jobs:]]
     
 
  jobs:
 
 
   build-docker-image:
 
   build-docker-image:
 
     [[runs-on: self-hosted]]
 
     [[runs-on: self-hosted]]
Line 28: Line 25:
 
       - name: Checkout
 
       - name: Checkout
 
         uses: [[actions/checkout@v3]]
 
         uses: [[actions/checkout@v3]]
 
+
 
       - name: Configure AWS Credentials
 
       - name: Configure AWS Credentials
 
         uses: actions/[[configure-aws-credentials]]@v2.0.0
 
         uses: actions/[[configure-aws-credentials]]@v2.0.0
 
         with:
 
         with:
 
           aws-region: eu-west-1
 
           aws-region: eu-west-1
 
+
 
       - name: Login to Private ECR
 
       - name: Login to Private ECR
 
         id: login-private-ecr
 
         id: login-private-ecr
Line 41: Line 38:
 
         id: build-image
 
         id: build-image
 
         [[env:]]
 
         [[env:]]
           #ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
+
           <nowiki>#ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}</nowiki>
           #IMAGE_TAG: ${{ github.sha }}
+
           <nowiki>#IMAGE_TAG: ${{ github.sha }}</nowiki>
 
           [[IMAGE_TAG]]: latest
 
           [[IMAGE_TAG]]: latest
 
         working-directory: ./your-working-dir
 
         working-directory: ./your-working-dir
Line 84: Line 81:
 
         uses: aws-actions/configure-aws-credentials@v1
 
         uses: aws-actions/configure-aws-credentials@v1
 
         with:
 
         with:
           aws-access-key-id: ${{ secrets.STAGING_DEPLOY_ACCESS_KEY }}
+
           <nowiki>aws-access-key-id: ${{ secrets.STAGING_DEPLOY_ACCESS_KEY }}</nowiki>
           aws-secret-access-key: ${{ secrets.STAGING_DEPLOY_ACCESS_SECRET }}
+
           <nowiki>aws-secret-access-key: ${{ secrets.STAGING_DEPLOY_ACCESS_SECRET }}</nowiki>
 
           aws-region: eu-west-1
 
           aws-region: eu-west-1
  
Line 91: Line 88:
 
         run: |
 
         run: |
 
           aws ecs update-service --cluster your-cluster-name --service your-service [[--force-new-deployment]]
 
           aws ecs update-service --cluster your-cluster-name --service your-service [[--force-new-deployment]]
 +
 +
 +
== Related ==
 +
* <code>[[docker-publish.yml]]</code>
 +
 +
== See also ==
 +
* {{GitHub Actions}}
 +
 +
[[Category:GitHub]]

Latest revision as of 12:00, 17 July 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[edit]

See also[edit]

Advertising: