-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (85 loc) · 3.32 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Community-bot
on:
push:
branches: ['main', 'deploy']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GITHUB_IDENTITY: tim80411
COMPOSE_FILE_PATH: /home/deploy
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Add Credentials
uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.FIRESTORE_ACCOUNT }}
filename: "firestore-service-account.json"
working-directory: "./creds"
- name: Log in to the container registy
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=deploy
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
APP_ID=${{secrets.APP_ID}}
DISCORD_TOKEN=${{secrets.DISCORD_TOKEN}}
PUBLIC_KEY=${{secrets.PUBLIC_KEY}}
DISCORD_GUILDID=${{secrets.DISCORD_GUILDID}}
CHANNEL_ID=${{secrets.CHANNEL_ID}}
PORT=${{secrets.PORT}}
labels: ${{ steps.meta.outputs.labels }}
- name: Scp compose file to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.PROD_SSH_DOMAIN }}
username: ${{ secrets.PROD_SSH_DEPLOY_USER }}
key: ${{ secrets.PROD_SSH_PRIVATE_KEY }}
source: './docker-compose.yml'
target: ${{ secrets.COMPOSE_FILE_PATH }}
# https://docs.github.com/en/packages/learn-github-packages/introduction-to-github-packages#authenticating-to-github-packages
- name: Ssh server and run docker-compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.PROD_SSH_DOMAIN }}
username: ${{ secrets.PROD_SSH_DEPLOY_USER }}
key: ${{ secrets.PROD_SSH_PRIVATE_KEY }}
script: |
echo "==Docker Login=="
echo "${{secrets.ACCESS_PACKAGE_TOKEN}}" | docker login ${{env.REGISTRY}} -u ${{env.GITHUB_IDENTITY}} --password-stdin
echo "==Pull Image=="
sudo docker-compose -f ${{env.COMPOSE_FILE_PATH}}/docker-compose.yml pull
echo "==Compose Up=="
sudo docker-compose -f ${{env.COMPOSE_FILE_PATH}}/docker-compose.yml up -d
echo "==Docker Logout=="
sudo docker logout ${{env.REGISTRY}}
echo "==Clean Up Prune Image=="
sudo docker image prune -f
# for saving money(limit: 500MB, [ref](https://docs.github.com/en/billing/managing-billing-for-github-packages/about-billing-for-github-packages))
- name: Delete Package Versions
uses: actions/[email protected]
with:
package-name: ${{ github.event.repository.name }}
package-type: container
min-versions-to-keep: 2