-
-
Notifications
You must be signed in to change notification settings - Fork 29
118 lines (110 loc) · 3.79 KB
/
deploy.yml
File metadata and controls
118 lines (110 loc) · 3.79 KB
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
name: Deploy
on:
workflow_dispatch:
inputs:
env:
required: true
type: choice
options:
- sirch
workflow_call:
inputs:
env:
description: Target environment for deployment
required: true
type: string
jobs:
stage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: 25
- name: Setup sbt
uses: sbt/setup-sbt@v1
- run: sbt stage
- uses: actions/upload-artifact@v7
with:
name: lila-search-app
path: modules/app/target/universal/stage
- uses: actions/upload-artifact@v7
with:
name: lila-search-ingestor
path: modules/ingestor-app/target/universal/stage
- uses: actions/upload-artifact@v7
with:
name: lila-search-cli
path: modules/ingestor-cli/target/universal/stage
deploy-components:
runs-on: ubuntu-latest
needs: stage
environment:
name: ${{ inputs.env }}
strategy:
fail-fast: false
max-parallel: 1
matrix:
include:
- artifact: lila-search-app
remote_dir: /home/lila-search
user: lila-search
restart_cmd: systemctl restart lila-search
- artifact: lila-search-ingestor
remote_dir: /home/lila-search-ingestor
user: lila-search-ingestor
restart_cmd: systemctl restart lila-search-ingestor
- artifact: lila-search-cli
remote_dir: /home/lila-search-cli
user: ""
restart_cmd: "" # no restart needed
concurrency:
group: deploy-${{ inputs.env }}
steps:
- name: Download artifact
uses: actions/download-artifact@v8
with:
name: ${{ matrix.artifact }}
path: stage
- name: Configure SSH
run: |
set -euo pipefail
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/id_deploy
chmod 600 ~/.ssh/id_deploy
echo "$SSH_KEY" > ~/.ssh/id_deploy
echo "$SSH_HOST $SSH_HOST_KEY" > ~/.ssh/known_hosts
cat >>~/.ssh/config <<END
Host deploy-host
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/id_deploy
StrictHostKeyChecking yes
END
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST_KEY: ${{ secrets.SSH_HOST_KEY }}
- name: Deploy via SSH
run: |
set -euo pipefail
if [ ! -d stage/bin ]; then
echo "ERROR: Expected staged artifact (stage/bin) not found. You skipped build jobs via workflow_dispatch."
echo "Either (a) run a normal CI build first, or (b) modify deploy job to build artifacts."
exit 1
fi
RSYNC_OPTIONS="--archive --no-o --no-g --force --delete --progress --compress --checksum --verbose --exclude RUNNING_PID --exclude '.git/'"
include="stage/bin stage/lib"
echo "Deploying ${{ matrix.artifact }} to ${{ matrix.remote_dir }}"
rsync $RSYNC_OPTIONS $include deploy-host:${{ matrix.remote_dir }}
echo "rsync complete (${{ matrix.artifact }})"
if [ -n "${{ matrix.restart_cmd }}" ]; then
echo "run restart: ${{ matrix.restart_cmd }}"
ssh deploy-host "chmod +x ${{ matrix.remote_dir }}/bin/${{ matrix.artifact }} && chown -R ${{ matrix.user }}:${{ matrix.user }} ${{ matrix.remote_dir }} && ${{ matrix.restart_cmd }}"
else
echo "No restart command defined for ${{ matrix.artifact }}."
fi
echo "Deploy complete (${{ matrix.artifact }})"