My-docker-publish.yml

From wikieduonline
Revision as of 22:50, 14 May 2023 by Welcome (talk | contribs) (Created page with " name: Build & deploy xxxxx container to stage env on: workflow_dispatch env: ACTIONS_RUNNER_DEBUG: true #AWS_REGION: MY_AWS_REGION # se...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
name: Build & deploy xxxxx container to stage env

on: workflow_dispatch 

env:
  ACTIONS_RUNNER_DEBUG: true
  #AWS_REGION: MY_AWS_REGION                   # set this to your preferred AWS region, e.g. us-west-1
  ECR_REPOSITORY: your-repo          # set this to your Amazon ECR repository name
  ECR_REGISTRY: 12312432424234.dkr.ecr.eu-west-1.amazonaws.com
  #ECS_SERVICE: MY_ECS_SERVICE                 # set this to your Amazon ECS service name
  #ECS_CLUSTER: MY_ECS_CLUSTER                 # set this to your Amazon ECS cluster name
  #ECS_TASK_DEFINITION: MY_ECS_TASK_DEFINITION # set this to the path to your Amazon ECS task definition
                                               # file, e.g. .aws/task-definition.json
  CONTAINER_NAME: your-container-name         # set this to the name of the container in the
                                              # containerDefinitions section of your task definition
      
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: $Template:Steps.login-ecr.outputs.registry
         #IMAGE_TAG: $Template: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: $Template:Secrets.STAGING DEPLOY ACCESS KEY
         aws-secret-access-key: $Template: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

Advertising: