-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (90 loc) · 3.34 KB
/
action.yml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Build && Deploy tsp-ui
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GIT_TAG: ${{ github.sha }}
jobs:
build-and-upload:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Cache Node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install yarn dependencies
run: yarn install
- name: Build tsp-ui
run: yarn build
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{ env.GIT_TAG }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- uses: convictional/trigger-workflow-and-wait@v1.3.0
with:
owner: WeiJiLab
repo: tsp-docker-compose-file
github_token: ${{ secrets.ZHU_TOKEN }}
workflow_file_name: action.yml
ref: master
wait_interval: 5
inputs: '{"image_tag": "${{ env.GIT_TAG }}"}'
propagate_failure: true
trigger_workflow: true
wait_workflow: true
deploy-to-ec2:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
needs: build-and-upload
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure AWS credentials from Test account
uses: aws-actions/configure-aws-credentials@master
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: GithubSession
# role-chaining: true
- name: Connect to EC2 using Session Manager
run: |
sudo apt install -y expect
# 启动 Session Manager 会话
# unbuffer aws ssm start-session --target ${{ secrets.AWS_INSTANCE_ID }}
unbuffer aws ssm start-session \
--document-name 'AWS-StartNonInteractiveCommand' \
--parameters '{"command": ["sudo sh -c \"cd /root && rm -rf tsp-docker-compose-file/ && git clone git@github.com:WeiJiLab/tsp-docker-compose-file.git && ls -al && cd tsp-docker-compose-file/tsp-ui/ && ls -al && echo ${{ secrets.ZHU_TOKEN }} | docker login ghcr.io -u ${{ secrets.GIT_HUB_USER }} --password-stdin && sudo docker-compose down && sudo docker-compose up -d \""]}' \
--target ${{ secrets.AWS_INSTANCE_ID }}