Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# reference:
# 1. https://github.com/docker/build-push-action/blob/master/docs/advanced/push-multi-registries.md
# 2. https://github.com/docker/build-push-action/blob/master/docs/advanced/share-image-jobs.md
# 3. https://github.com/marketplace/actions/unregistry-docker-push-action

name: Deploy to Production environment
on:
push:
tags:
- v*
env:
ARTIFACT_PATH: artifact.tar
BOX_NAME: kys-ows
BOX_URL: kaiyuanshe/kys-ows
DOCKER_BUILD_SUMMARY: false
Expand Down Expand Up @@ -39,6 +39,7 @@ jobs:
${{ secrets.ENV_FILE }}
VERCEL_URL=kaiyuanshe.cn
EOF

- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

Expand All @@ -48,36 +49,41 @@ jobs:
context: .
platforms: linux/amd64
tags: ${{ env.BOX_URL }}:latest
outputs: type=docker,dest=${{ env.ARTIFACT_PATH }}
load: true # Load image to local Docker daemon for unregistry
# use cache from GitHub Actions
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Pick Docker Compose
run: |
mkdir ./build
mv ${{ env.ARTIFACT_PATH }} ./docker-compose.yml ./start.sh ./build
- name: Add server to known hosts
run: ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts

- name: Transport Image
uses: appleboy/scp-action@v0.1.7
- name: Deploy Docker image to server
uses: SonOfBytes/unregistry-action@v0.1.0
with:
source: ./build/*.*
target: /tmp/${{ env.BOX_NAME }}
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.SSH_KEY }}
strip_components: 1
image: ${{ env.BOX_URL }}:latest
destination: ${{ secrets.USER }}@${{ secrets.HOST }}
ssh_key: ${{ secrets.SSH_KEY }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个项目用的是密码认证。

Copy link
Contributor Author

@luojiyin1987 luojiyin1987 Jun 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonOfBytes/unregistry-action#1 已经提issue, 等维护者的确认。

psviderski/unregistry#16 也往更上游提 issue 寻求帮助。


- name: Run Image
- name: Deploy Docker Compose and start services
uses: garygrossgarten/github-action-ssh@release
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.SSH_KEY }}
command: |
mkdir -p ~/${{ env.BOX_NAME }}
cd /tmp/${{ env.BOX_NAME }}
mv docker-compose.yml start.sh ~/${{ env.BOX_NAME }}
cd ~/${{ env.BOX_NAME }}
chmod +x start.sh
echo '${{ secrets.SSH_KEY }}' | sudo -S ./start.sh /tmp/${{ env.BOX_NAME }}/${{ env.ARTIFACT_PATH }}

# Check if docker-compose.yml exists
if [ ! -f docker-compose.yml ]; then
echo "Error: docker-compose.yml not found in ~/${{ env.BOX_NAME }}"
echo "Please create a docker-compose.yml file before deployment"
exit 1
fi

# Stop existing containers and start new ones
docker-compose down -v --remove-orphans
docker-compose up -d

# Clean up unused images
docker image prune -a -f