Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Wcc723 committed Oct 4, 2023
1 parent 9869ee8 commit 553fa2d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/deploy-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy to Portainer

on:
push:
branches:
- docker-compose

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sample-node-express:latest
push: true

- name: Install SSH key # 第二步,安裝 SSH 密鑰
uses: webfactory/[email protected] # 使用第三方的 ssh-agent 動作
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }} # 從 GitHub Secrets 中取得私鑰

- name: Update known_hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan ${{HOST_NAME}} >> ~/.ssh/known_hosts
- name: Copy docker-compose.yml to remote server
run: |
scp ./docker-compose.yml root@${{HOST_NAME}}:/root/docker-compose.yml
- name: Deploy with Docker Compose
run: |
ssh root@${{HOST_NAME}} "docker-compose -f /root/docker-compose.yml up -d"
env:
ENV_VARIABLE: ${{ secrets.ENV_VARIABLE }}
MONGO_ROOT_USERNAME: ${{ secrets.MONGO_ROOT_USERNAME }}
MONGO_ROOT_PASSWORD: ${{ secrets.MONGO_ROOT_PASSWORD }}

0 comments on commit 553fa2d

Please sign in to comment.