Skip to content

Commit 4ad3f86

Browse files
committed
update yml job
1 parent 0a63e22 commit 4ad3f86

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

.github/workflows/server.yml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,52 @@ on:
99
jobs:
1010
build-and-push:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
1216
steps:
13-
- uses: actions/checkout@v4
14-
- uses: docker/setup-buildx-action@v3
15-
- uses: docker/login-action@v3
17+
- name: Checkout repo
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Log in to GHCR
24+
uses: docker/login-action@v3
1625
with:
1726
registry: ghcr.io
1827
username: ${{ github.actor }}
1928
password: ${{ secrets.GITHUB_TOKEN }}
20-
- uses: docker/build-push-action@v6
29+
30+
- name: Build and push image
31+
uses: docker/build-push-action@v6
2132
with:
2233
context: ./plate-server
23-
push: true
24-
tags: ghcr.io/whatnext-id/plate-code-detector:latest
34+
push: ${{ github.event_name == 'push' }}
35+
tags: plate-code-detector:latest
2536
cache-from: type=gha
2637
cache-to: type=gha,mode=max
2738

2839
deploy:
29-
needs: build-and-push
3040
runs-on: ubuntu-latest
41+
needs: build-and-push
42+
if: github.event_name == 'push'
43+
3144
steps:
45+
- name: Setup SSH
46+
run: |
47+
mkdir -p ~/.ssh
48+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
49+
chmod 600 ~/.ssh/id_ed25519
50+
ssh-keyscan -p 22 -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
51+
3252
- name: Deploy to server
3353
run: |
3454
ssh -i ~/.ssh/id_ed25519 ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF'
55+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
3556
cd ~/PlateCode/plate-server
3657
docker compose pull
37-
docker compose up -d # no --build !
38-
docker image prune -f # no -a !
58+
docker compose --project-name platecode up -d
59+
docker image prune -f
3960
EOF

0 commit comments

Comments
 (0)