Skip to content

Commit a755e61

Browse files
authored
Create deploy.yml
1 parent c182ff5 commit a755e61

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# This workflow will build and push a new container image to Amazon ECR,
2+
# and then will deploy a new task definition to Amazon ECS, when there is a push to the "main" branch.
3+
#
4+
# To use this workflow, you will need to complete the following set-up steps:
5+
#
6+
# 1. Create an ECR repository to store your images.
7+
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`.
8+
# Replace the value of the `ECR_REPOSITORY` environment variable in the workflow below with your repository's name.
9+
# Replace the value of the `AWS_REGION` environment variable in the workflow below with your repository's region.
10+
#
11+
# 2. Create an ECS task definition, an ECS cluster, and an ECS service.
12+
# For example, follow the Getting Started guide on the ECS console:
13+
# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun
14+
# Replace the value of the `ECS_SERVICE` environment variable in the workflow below with the name you set for the Amazon ECS service.
15+
# Replace the value of the `ECS_CLUSTER` environment variable in the workflow below with the name you set for the cluster.
16+
#
17+
# 3. Store your ECS task definition as a JSON file in your repository.
18+
# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`.
19+
# Replace the value of the `ECS_TASK_DEFINITION` environment variable in the workflow below with the path to the JSON file.
20+
# Replace the value of the `CONTAINER_NAME` environment variable in the workflow below with the name of the container
21+
# in the `containerDefinitions` section of the task definition.
22+
#
23+
# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
24+
# See the documentation for each action used below for the recommended IAM policies for this IAM user,
25+
# and best practices on handling the access key credentials.
26+
27+
name: Deploy to Amazon ECS
28+
29+
on:
30+
release:
31+
types: [published]
32+
33+
env:
34+
AWS_REGION: "us-east-2" # set this to your preferred AWS region, e.g. us-west-1
35+
ECR_REPOSITORY: "oclweb3" # set this to your Amazon ECR repository name
36+
ECS_SERVICE: "qa-web3" # set this to your Amazon ECS service name
37+
ECS_CLUSTER: "ocl-qa-demo" # set this to your Amazon ECS cluster name
38+
39+
permissions:
40+
contents: read
41+
42+
jobs:
43+
deploy:
44+
name: Deploy
45+
runs-on: ubuntu-latest
46+
environment: qa
47+
48+
steps:
49+
- name: Configure AWS credentials
50+
uses: aws-actions/configure-aws-credentials@v1
51+
with:
52+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
53+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
54+
aws-region: ${{ env.AWS_REGION }}
55+
- name: Login to Amazon ECR
56+
id: login-ecr
57+
uses: aws-actions/amazon-ecr-login@v1
58+
- uses: actions/checkout@v3
59+
- name: Add GITHUB_SHA_SHORT env property with commit short sha
60+
run: echo "GITHUB_SHA_SHORT=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
61+
- name: Push image to Amazon ECR
62+
id: push-image
63+
env:
64+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
65+
IMAGE_TAG: 3.0-alpha-${{env.GITHUB_SHA_SHORT}}
66+
run: |
67+
# Build a docker container and
68+
# push it to ECR so that it can
69+
# be deployed to ECS.
70+
docker pull openconceptlab/oclweb3:$IMAGE_TAG
71+
docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
72+
docker tag openconceptlab/oclweb3:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa
73+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
74+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa
75+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
76+
- name: Download task definition
77+
run: |
78+
aws ecs describe-task-definition --task-definition $ECS_SERVICE --query taskDefinition > task-definition.json
79+
- name: Fill in the new image ID in the Amazon ECS task definition
80+
id: task-def
81+
uses: aws-actions/amazon-ecs-render-task-definition@v1
82+
with:
83+
task-definition: "task-definition.json"
84+
container-name: ${{ env.ECS_SERVICE }}
85+
image: ${{ steps.push-image.outputs.image }}
86+
87+
- name: Deploy Amazon ECS task definition
88+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
89+
with:
90+
task-definition: ${{ steps.task-def.outputs.task-definition }}
91+
service: ${{ env.ECS_SERVICE }}
92+
cluster: ${{ env.ECS_CLUSTER }}

0 commit comments

Comments
 (0)