forked from johnpapa/node-hello
-
Notifications
You must be signed in to change notification settings - Fork 40
78 lines (60 loc) · 2.96 KB
/
Copy pathdocker-image.yml
File metadata and controls
78 lines (60 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Docker Image CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag lidorlg/lidor-node-devops-sce:5
- name: login and push to docker hub
run: |
docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
docker push lidorlg/lidor-node-devops-sce:5
- name: login to AWS
uses: aws-actions/configure-aws-credentials@v6.2.0
with:
# AWS Region, e.g. us-east-2
aws-region: us-east-1
# AWS Access Key ID. Provide this key if you want to assume a role using access keys rather than a web identity token.
aws-access-key-id: ${{ secrets.ACCESS_KEY }}
# AWS Secret Access Key. Required if aws-access-key-id is provided.
aws-secret-access-key: ${{ secrets.SECRET_KEY }}
- name: deploy to ecs
run: |
TASK_DEF=$(aws ecs describe-task-definition --task-definition "node-demo-azrieli")
NEW_TASK_DEF=$(echo "$TASK_DEF" | jq '.taskDefinition | .containerDefinitions[0].image = "lidorlg/lidor-node-devops-sce:5" | del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .compatibilities, .registeredAt, .registeredBy)')
# 2. Register New Revision
NEW_TASK_INFO=$(aws ecs register-task-definition --cli-input-json "$NEW_TASK_DEF")
# 3. Update Service to use new revision
aws ecs update-service --cluster "lidor-demo-azrieli" --service "node-demo-azrieli-service-b553awup" --task-definition "node-demo-azrieli"
# Step 5.1: Download current ECS task definition
# - name: Download current task definition
# run: |
# aws ecs describe-task-definition \
# --task-definition node-demo-azrieli \
# --query taskDefinition > task-definition.json
# # Step 5.2: Clean the task definition by removing metadata
# - name: Clean task definition
# run: |
# jq 'del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .compatibilities, .registeredAt, .deregisteredAt, .registeredBy, .enableFaultInjection)' task-definition.json > cleaned-task-definition.json
# mv cleaned-task-definition.json task-definition.json
# - name: Fill in the new image ID in the Amazon ECS task definition
# id: task-def
# uses: aws-actions/amazon-ecs-render-task-definition@v1
# with:
# task-definition: task-definition.json
# container-name: node-demo
# image: lidorlg/lidor-node-devops-sce:5
# - name: deploy the new image to ecs
# uses: aws-actions/amazon-ecs-deploy-task-definition@v2
# with:
# task-definition: task-definition.json
# service: node-demo-azrieli-service-b553awup
# cluster: lidor-demo-azrieli
# wait-for-service-stability: true