Skip to content

[fix]: update action.yml for all CICD #77

[fix]: update action.yml for all CICD

[fix]: update action.yml for all CICD #77

Workflow file for this run

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: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- 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 mackizhu --password-stdin && docker-compose down && sudo docker-compose up -d \""]}' \
--target ${{ secrets.AWS_INSTANCE_ID }}