-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (139 loc) · 5.39 KB
/
deployment.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Deploy Application
on: workflow_dispatch
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout the project
uses: actions/checkout@v4
- name: Set up JDK 21 for x64
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2.4.2
- name: Run the Gradle Build
run: ./gradlew clean build
- name: Set Project name and version as environment variables
run: |
echo "${{ secrets.DOCKERHUB_USERNAME}}/$(./gradlew -q projectName):$(./gradlew -q version)" > image_name.txt
cat image_name.txt
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: docker-artifacts
path: |
build/libs/*.jar
image_name.txt
compose.yml
compose.prod.yml
docker-upload:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout the project
uses: actions/checkout@v4
- name: Pull cached artifact
uses: actions/download-artifact@v3
with:
name: docker-artifacts
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download Image Name File
uses: actions/download-artifact@v3
with:
name: docker-artifacts
- name: Set variable with docker image name
run: |
content=$(cat ./image_name.txt)
echo "DOCKER_IMAGE_NAME=$content" >> $GITHUB_ENV
shell: bash
- name: Find and set JAR file
id: SET_JAR_FILE
run: |
JAR_FILE=$(find ./build/libs -type f -name "rivenbot-*.jar")
if [ -z "$JAR_FILE" ]; then
echo "::debug::No JAR file found in build/libs with the specified pattern"
exit 1
fi
echo "JAR_FILE=$JAR_FILE" >> "$GITHUB_OUTPUT"
shell: bash
- name: Build and Push
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.DOCKER_IMAGE_NAME }}
build-args: JAR_FILE=${{ steps.SET_JAR_FILE.outputs.JAR_FILE }}
context: .
pre-deploy:
needs: docker-upload
runs-on: ubuntu-latest
steps:
- name: Pull Saved Artifacts
uses: actions/download-artifact@v3
with:
name: docker-artifacts
- name: Set variable with docker image name
run: |
content=$(cat ./image_name.txt)
echo "DOCKER_IMAGE_NAME=$content" >> $GITHUB_ENV
shell: bash
- name: Prepare environment data
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.DROPLET_HOST }}
username: ${{ secrets.DROPLET_USERNAME }}
key: ${{ secrets.DROPLET_PRIVATE_TOKEN }}
script: |
# Change to working directory
cd riven_of_a_thousand_servers/
# Setup .env file
rm -f .env
echo "BUNGIE_API_KEY=${{ secrets.BUNGIE_API_KEY }}" > .env
echo "BUNGIE_CLIENT_ID=${{ secrets.BUNGIE_CLIENT_ID }}" >> .env
echo "BUNGIE_CLIENT_SECRET=${{ secrets.BUNGIE_CLIENT_SECRET }}" >> .env
echo "DOCKER_IMAGE_NAME=${{ env.DOCKER_IMAGE_NAME }}" >> .env
echo "DISCORD_BOT_PUBLIC_KEY=${{ secrets.DISCORD_BOT_PUBLIC_KEY }}" >> .env
echo "DISCORD_BOT_TOKEN=${{ secrets.DISCORD_BOT_TOKEN }}" >> .env
echo "DISCORD_CLIENT_ID=${{ secrets.DISCORD_CLIENT_ID }}" >> .env
echo "DISCORD_CLIENT_SECRET=${{ secrets.DISCORD_CLIENT_SECRET }}" >> .env
echo "DISCORD_APPLICATION_ID=${{ secrets.DISCORD_APPLICATION_ID }}" >> .env
echo "DISCORD_BOT_PUBLIC_KEY=${{ secrets.DISCORD_BOT_PUBLIC_KEY }}" >> .env
echo "MONGO_DB_ROOT_USERNAME=${{ secrets.MONGO_INITDB_ROOT_USERNAME }}" >> .env
echo "MONGO_DB_ROOT_PASSWORD=${{ secrets.MONGO_INITDB_ROOT_PASSWORD }}" >> .env
echo "GRAFANA_ADMIN_USERNAME=${{ secrets.GRAFANA_ADMIN_USERNAME }}" >> .env
echo "GRAFANA_ADMIN_PASSWORD=${{ secrets.GRAFANA_ADMIN_PASSWORD }}" >> .env
# Change permissions on .env file
chmod 600 .env
- name: Prepare Docker artifacts
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DROPLET_HOST }}
username: ${{ secrets.DROPLET_USERNAME }}
key: ${{ secrets.DROPLET_PRIVATE_TOKEN }}
source: "compose.yml,compose.prod.yml"
target: ./riven_of_a_thousand_servers/
deploy:
needs: pre-deploy
runs-on: ubuntu-latest
steps:
- name: Prepare environment data
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.DROPLET_HOST }}
username: ${{ secrets.DROPLET_USERNAME }}
key: ${{ secrets.DROPLET_PRIVATE_TOKEN }}
script: |
# Checkout working directory
cd riven_of_a_thousand_servers/
# Stop current Docker compose
docker compose down
# Start Docker compose
docker compose -f compose.yml -f compose.prod.yml up -d