-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
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 }} |