-
Notifications
You must be signed in to change notification settings - Fork 1
72 lines (64 loc) · 4.34 KB
/
docker-deploy.yaml
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
name: Build and Push Docker Image
on:
push:
branches: [ master ]
paths:
- "GuildWarsPartySearch.Common/**"
- "GuildWarsPartySearch/**"
- "Dockerfile-Server"
- ".github/workflows/docker-deploy.yaml"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Install sshpass
run: sudo apt-get update && sudo apt-get install -y sshpass
- name: Replace secrets in configuration
shell: pwsh
run: |
$jsonContent = Get-Content -Raw -Path GuildWarsPartySearch\Config.Production.json | ConvertFrom-Json
$trimmedIps = "${{ secrets.COMMA_SEPARATED_IPS }}" -split ',' | ForEach-Object { $_.Trim() }
$newAddressesArray = $jsonContent.IpWhitelistOptions.Addresses + $trimmedIps
$jsonContent.IpWhitelistOptions.Addresses = $newAddressesArray
$updatedJsonContent = $jsonContent | ConvertTo-Json -Depth 32
Set-Content -Path Config.json -Value $updatedJsonContent
- name: Build docker image
run: |
echo "Building docker image"
docker build -t guildwarspartysearch.server -f Dockerfile-Server .
echo "Exporting docker image"
docker save -o guildwarspartysearch.server.tar guildwarspartysearch.server
echo "Exported docker image"
- name: Deploy Docker image to host
shell: pwsh
run: |
echo "Setting up staging folder"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "mkdir -p /home/guildwarspartysearch/staging"
echo "Uploading image"
sshpass -p "${{ secrets.HOST_PASS }}" scp -o StrictHostKeyChecking=no guildwarspartysearch.server.tar ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }}:/home/guildwarspartysearch/staging
echo "Uploading configuration"
sshpass -p "${{ secrets.HOST_PASS }}" scp -o StrictHostKeyChecking=no Config.json ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }}:/home/guildwarspartysearch/staging
echo "Stopping running contianer"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker stop partysearch"
echo "Backing up database"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker cp partysearch:/app/partysearches.db /home/guildwarspartysearch/staging/partysearches.db"
echo "Stopping and removing old containers"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker rm partysearch && docker rmi -f guildwarspartysearch.server:latest"
echo "Loading new image"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker load -i /home/guildwarspartysearch/staging/guildwarspartysearch.server.tar"
echo "Creating container"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker create --name partysearch -p 8080:80 guildwarspartysearch.server:latest"
echo "Copying configuration into container"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker cp /home/guildwarspartysearch/staging/Config.json partysearch:/app/Config.json"
echo "Copying database backup into container"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker cp /home/guildwarspartysearch/staging/partysearches.db partysearch:/app/partysearches.db"
echo "Starting container"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "docker start partysearch"
echo "Cleaning up"
sshpass -p "${{ secrets.HOST_PASS }}" ssh -o StrictHostKeyChecking=no ${{ secrets.HOST_USER }}@${{ secrets.HOST_ADDRESS }} "rm -f /home/guildwarspartysearch/staging/guildwarspartysearch.server.tar && rm -f /home/guildwarspartysearch/staging/Config.json"