Deploy sxcloud to Server #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy sxcloud to Server | |
on: | |
schedule: | |
- cron: '0 10 * * 2' # 每周二上午10点 | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_REGISTRY: sxwl-registry.cn-beijing.cr.aliyuncs.com | |
NAMESPACE: sxwl-ai | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Login to Docker Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract and Build Images | |
id: extract_and_build | |
run: | | |
cd ui | |
docker build -t $DOCKER_REGISTRY/$NAMESPACE/webui:latest . | |
docker push $DOCKER_REGISTRY/$NAMESPACE/webui:latest | |
- name: Configure SSH | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY }} | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -t rsa sxwl.ai >> ~/.ssh/known_hosts | |
- name: Deploy to Hosting Service | |
run: | | |
ssh [email protected] << EOF | |
GO_GATEWAY_CONTAINER=\$(sudo docker ps --format '{{.Names}} {{.Image}}' | grep 'sxwl-ai/go-gateway' | awk '{print \$1}') | |
sudo docker pull $DOCKER_REGISTRY/$NAMESPACE/webui:latest | |
sudo docker stop webui || true | |
sudo docker rm webui || true | |
sudo docker run -d --name webui --link \$GO_GATEWAY_CONTAINER:go-gateway-service -p 8088:80 $DOCKER_REGISTRY/$NAMESPACE/webui:latest | |
EOF |