Skip to content

Commit caa3871

Browse files
Merge remote-tracking branch 'origin/dev'
2 parents abce39c + 391c98b commit caa3871

44 files changed

Lines changed: 1464 additions & 170 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy.yaml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: RockShell Deployment
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ENVIRONMENT:
7+
required: true
8+
type: string
9+
# on the second run we read the deploy name from the input
10+
# this is to make sure that DEPLOY_NAME is the same for all jobs
11+
DEPLOY_NAME:
12+
required: true
13+
type: string
14+
secrets:
15+
SSH_KEY:
16+
required: true
17+
CI_TOKEN:
18+
required: false
19+
DBPASS:
20+
required: true
21+
USERAUTHSALT:
22+
required: true
23+
24+
jobs:
25+
setup:
26+
uses: baumrock/RockShell/.github/workflows/setup.yaml@dev
27+
with:
28+
ENVIRONMENT: ${{ inputs.ENVIRONMENT }}
29+
DEPLOY_NAME: ${{ inputs.DEPLOY_NAME }}
30+
secrets:
31+
SSH_KEY: ${{ secrets.SSH_KEY }}
32+
CI_TOKEN: ${{ secrets.CI_TOKEN }}
33+
DBPASS: ${{ secrets.DBPASS }}
34+
USERAUTHSALT: ${{ secrets.USERAUTHSALT }}
35+
36+
rsync:
37+
runs-on: ubuntu-latest
38+
needs: [setup]
39+
environment: ${{ inputs.ENVIRONMENT }}
40+
steps:
41+
- name: 🕵 Setup SSH
42+
run: |
43+
44+
# Setup SSH
45+
install -m 600 -D /dev/null ~/.ssh/id_rsa
46+
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
47+
echo "${{ vars.KNOWN_HOSTS }}" > ~/.ssh/known_hosts
48+
echo "✅ SSH setup"
49+
50+
- name: 🚩 Set deployment flag
51+
run: |
52+
53+
# create deploying flag file
54+
sshExec() {
55+
USER=${{ needs.setup.outputs.SSH_USER }}
56+
HOST=${{ needs.setup.outputs.SSH_HOST }}
57+
PORT=${{ needs.setup.outputs.SSH_PORT }}
58+
ssh $USER@$HOST -p$PORT "$@"
59+
}
60+
DST=${{ needs.setup.outputs.DEPLOY_DST }}
61+
sshExec "touch $DST/deploying"
62+
echo "✅ Deployment flag set"
63+
64+
- name: 🚛 Checkout
65+
uses: actions/checkout@v4
66+
with:
67+
submodules: ${{ needs.setup.outputs.SUBMODULES }}
68+
token: ${{ secrets.CI_TOKEN }}
69+
70+
- name: 📋 List files in DEPLOY_SRC
71+
run: ls ${{ github.workspace }}${{ needs.setup.outputs.DEPLOY_SRC }}
72+
73+
- name: 🚚 Deploy via RSYNC and Set Permissions
74+
run: |
75+
76+
# prepare variables
77+
USER=${{ needs.setup.outputs.SSH_USER }}
78+
HOST=${{ needs.setup.outputs.SSH_HOST }}
79+
PORT=${{ needs.setup.outputs.SSH_PORT }}
80+
DST=${{ needs.setup.outputs.DEPLOY_DST }}
81+
NAME=${{ needs.setup.outputs.DEPLOY_NAME }}
82+
FROM=${{ github.workspace }}${{ needs.setup.outputs.DEPLOY_SRC }}
83+
TO=$USER@$HOST:$DST/tmp-$NAME
84+
85+
# rsync the files to the server
86+
rsync -avz --chmod=D755,F644 \
87+
--exclude '.git' \
88+
--exclude '/.ddev' \
89+
${{ needs.setup.outputs.RSYNC }} \
90+
-e "ssh -p$PORT" $FROM $TO
91+
echo "✅ rsync completed"
92+
93+
execute:
94+
needs: [rsync, setup]
95+
runs-on: ubuntu-latest
96+
environment: ${{ inputs.ENVIRONMENT }}
97+
steps:
98+
- name: 🐘 Execute Deployment
99+
run: |
100+
101+
# Setup SSH
102+
install -m 600 -D /dev/null ~/.ssh/id_rsa
103+
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
104+
echo "${{ vars.KNOWN_HOSTS }}" > ~/.ssh/known_hosts
105+
sshExec() {
106+
USER=${{ needs.setup.outputs.SSH_USER }}
107+
HOST=${{ needs.setup.outputs.SSH_HOST }}
108+
PORT=${{ needs.setup.outputs.SSH_PORT }}
109+
ssh $USER@$HOST -p$PORT "$@"
110+
}
111+
echo "✅ SSH setup"
112+
113+
# execute the deployment script
114+
DST=${{ needs.setup.outputs.DEPLOY_DST }}
115+
NAME=${{ needs.setup.outputs.DEPLOY_NAME }}
116+
KEEP=${{ needs.setup.outputs.KEEP }}
117+
sshExec "php $DST/tmp-$NAME/RockShell/deploy.php --keep $KEEP"
118+
echo "✅ Deployment script executed"
119+
120+
- name: 🗑️ Cleanup
121+
run: |
122+
123+
# remove all tmp-release-* folders
124+
echo "Remove all tmp-release-* folders"
125+
sshExec() {
126+
USER=${{ needs.setup.outputs.SSH_USER }}
127+
HOST=${{ needs.setup.outputs.SSH_HOST }}
128+
PORT=${{ needs.setup.outputs.SSH_PORT }}
129+
ssh $USER@$HOST -p$PORT "$@"
130+
}
131+
DST=${{ needs.setup.outputs.DEPLOY_DST }}
132+
sshExec "rm -rf $DST/tmp-release-*"
133+
echo "✅ tmp-release-* folders removed"
134+
135+
# remove deploying flag file
136+
echo "Remove deploying flag file"
137+
sshExec "rm -f $DST/deploying"
138+
echo "✅ Deployment flag removed"

.github/workflows/releases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- name: conventional Changelog Action
1414
id: changelog
1515
uses: TriPSs/conventional-changelog-action@v5.1.0

.github/workflows/setup.yaml

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
name: RockShell Deployment Setup
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ENVIRONMENT:
7+
required: true
8+
type: string
9+
SSH:
10+
required: false
11+
type: boolean
12+
default: false
13+
DEPLOY_NAME:
14+
required: false
15+
type: string
16+
secrets:
17+
SSH_KEY:
18+
required: true
19+
CI_TOKEN:
20+
required: false
21+
DBPASS:
22+
required: true
23+
USERAUTHSALT:
24+
required: true
25+
outputs:
26+
DEPLOY_DST:
27+
value: ${{ jobs.setup.outputs.DEPLOY_DST }}
28+
DEPLOY_NAME:
29+
value: ${{ jobs.setup.outputs.DEPLOY_NAME }}
30+
SSH_PORT:
31+
value: ${{ jobs.setup.outputs.SSH_PORT }}
32+
DRY:
33+
value: ${{ jobs.setup.outputs.DRY }}
34+
SUBMODULES:
35+
value: ${{ jobs.setup.outputs.SUBMODULES }}
36+
BRANCH:
37+
value: ${{ jobs.setup.outputs.BRANCH }}
38+
SSH_USER:
39+
value: ${{ jobs.setup.outputs.SSH_USER }}
40+
SSH_HOST:
41+
value: ${{ jobs.setup.outputs.SSH_HOST }}
42+
DEPLOY_SRC:
43+
value: ${{ jobs.setup.outputs.DEPLOY_SRC }}
44+
RSYNC:
45+
value: ${{ jobs.setup.outputs.RSYNC }}
46+
KEEP:
47+
value: ${{ jobs.setup.outputs.KEEP }}
48+
49+
jobs:
50+
setup:
51+
runs-on: ubuntu-latest
52+
environment: ${{ inputs.ENVIRONMENT }}
53+
outputs:
54+
DEPLOY_NAME: ${{ steps.setupvars.outputs.DEPLOY_NAME }}
55+
DEPLOY_DST: ${{ steps.setupvars.outputs.DEPLOY_DST }}
56+
DRY: ${{ steps.setupvars.outputs.DRY }}
57+
SUBMODULES: ${{ steps.setupvars.outputs.SUBMODULES }}
58+
BRANCH: ${{ steps.setupvars.outputs.BRANCH }}
59+
SSH_USER: ${{ steps.setupvars.outputs.SSH_USER }}
60+
SSH_HOST: ${{ steps.setupvars.outputs.SSH_HOST }}
61+
DEPLOY_SRC: ${{ steps.setupvars.outputs.DEPLOY_SRC }}
62+
RSYNC: ${{ steps.setupvars.outputs.RSYNC }}
63+
KEEP: ${{ steps.setupvars.outputs.KEEP }}
64+
SSH_PORT: ${{ steps.setupvars.outputs.SSH_PORT }}
65+
steps:
66+
- name: 🛠 Setup Variables
67+
id: setupvars
68+
run: |
69+
70+
# Setup variables
71+
HAS_ERRORS=false
72+
SSH_PORT="${{ vars.SSH_PORT || 22 }}"
73+
DRY="${{ vars.DRY == 'true' }}"
74+
SUBMODULES="${{ vars.SUBMODULES == 'true' }}"
75+
BRANCH="${GITHUB_REF##*/}"
76+
SSH_USER="${{ vars.SSH_USER }}"
77+
SSH_HOST="${{ vars.SSH_HOST }}"
78+
KNOWN_HOSTS="${{ vars.KNOWN_HOSTS }}"
79+
DEPLOY_SRC="${{ vars.DEPLOY_SRC || '/' }}"
80+
DEPLOY_DST="${{ vars.DEPLOY_DST }}"
81+
RSYNC="${{ vars.RSYNC }}"
82+
KEEP="${{ vars.KEEP || 2 }}"
83+
DEPLOY_NAME=${{ inputs.DEPLOY_NAME }}
84+
if [ -z "$DEPLOY_NAME" ]; then
85+
SHORT_SHA=$(echo ${GITHUB_SHA} | cut -c1-8)
86+
CURRENT_DATE=$(date +%Y-%m-%d--%H-%M-%S)
87+
DEPLOY_NAME="release---$CURRENT_DATE---$SHORT_SHA"
88+
fi
89+
DBHOST="${{ vars.DBHOST || 'localhost' }}"
90+
DBNAME="${{ vars.DBNAME }}"
91+
DBUSER="${{ vars.DBUSER || vars.DBNAME }}"
92+
DBPASS="${{ secrets.DBPASS }}"
93+
USERAUTHSALT="${{ secrets.USERAUTHSALT }}"
94+
HTTPHOSTS="${{ vars.HTTPHOSTS }}"
95+
DEBUG="${{ vars.DEBUG || false }}"
96+
97+
# special case for CI_TOKEN
98+
TOKEN="✅ TOKEN: not needed"
99+
if [ "$SUBMODULES" = "true" ]; then
100+
if [ -z "${{ secrets.CI_TOKEN }}" ]; then
101+
TOKEN="❌ TOKEN: secret is empty"
102+
HAS_ERRORS=true
103+
else
104+
TOKEN="✅ TOKEN: secret exists"
105+
fi
106+
fi
107+
108+
echo "----- General Setup -----"
109+
echo "✅ ENVIRONMENT: ${{ inputs.ENVIRONMENT }}"
110+
echo "✅ BRANCH: $BRANCH"
111+
echo "✅ SUBMODULES: $SUBMODULES"
112+
echo "✅ DEPLOY_NAME: $DEPLOY_NAME"
113+
echo "$TOKEN"
114+
echo "✅ DRY: $DRY"
115+
116+
echo "----- SSH Setup -----"
117+
118+
if [ -n "$SSH_USER" ]; then
119+
echo "✅ SSH_USER: $SSH_USER"
120+
else
121+
echo "❌ SSH_USER: variable must be set"
122+
HAS_ERRORS=true
123+
fi
124+
125+
if [ -n "$SSH_HOST" ]; then
126+
echo "✅ SSH_HOST: $SSH_HOST"
127+
else
128+
echo "❌ SSH_HOST: variable must be set"
129+
HAS_ERRORS=true
130+
fi
131+
132+
echo "✅ SSH_PORT: $SSH_PORT"
133+
134+
if [ -n "$KNOWN_HOSTS" ]; then
135+
echo "✅ KNOWN_HOSTS: exists"
136+
else
137+
echo "❌ KNOWN_HOSTS: variable must be set"
138+
HAS_ERRORS=true
139+
fi
140+
141+
echo "----- Deployment Setup -----"
142+
143+
echo "✅ DEPLOY_SRC: $DEPLOY_SRC"
144+
if [[ "$DEPLOY_DST" == */ ]]; then
145+
echo "⚠️ DEPLOY_DST: trailing slash removed"
146+
DEPLOY_DST=${DEPLOY_DST%/}
147+
fi
148+
if [ -n "$DEPLOY_DST" ]; then
149+
echo "✅ DEPLOY_DST: $DEPLOY_DST"
150+
else
151+
echo "❌ DEPLOY_DST: variable must be set"
152+
HAS_ERRORS=true
153+
fi
154+
155+
echo "✅ RSYNC: $RSYNC"
156+
echo "✅ KEEP: $KEEP"
157+
158+
echo "----- Config Setup -----"
159+
160+
echo "✅ DBHOST: $DBHOST"
161+
if [ -n "$DBNAME" ]; then
162+
echo "✅ DBNAME: $DBNAME"
163+
else
164+
echo "❌ DBNAME: variable must be set"
165+
HAS_ERRORS=true
166+
fi
167+
echo "✅ DBUSER: $DBUSER"
168+
if [ -n "$DBPASS" ]; then
169+
echo "✅ DBPASS: $DBPASS"
170+
else
171+
echo "❌ DBPASS: secret must be set"
172+
HAS_ERRORS=true
173+
fi
174+
if [ -n "$USERAUTHSALT" ]; then
175+
echo "✅ USERAUTHSALT: $USERAUTHSALT"
176+
else
177+
echo "❌ USERAUTHSALT: secret must be set"
178+
HAS_ERRORS=true
179+
fi
180+
# if httphosts does not start with [ and end with ] show error
181+
if [[ ! "$HTTPHOSTS" =~ ^\[.*\]$ ]]; then
182+
echo "❌ HTTPHOSTS: must start with [ and end with ] (php array syntax)"
183+
HAS_ERRORS=true
184+
else
185+
echo "✅ HTTPHOSTS: $HTTPHOSTS"
186+
fi
187+
echo "✅ DEBUG: $DEBUG"
188+
189+
echo "-----"
190+
191+
if [ "$HAS_ERRORS" = true ]; then
192+
exit 1
193+
else
194+
echo "✅ All required variables are set"
195+
fi
196+
197+
if [ "$DRY" = true ]; then
198+
echo "⚠️ DRY run - skipping deployment"
199+
fi
200+
201+
# Output all variables for workflow outputs
202+
echo "DRY=$DRY" >> $GITHUB_OUTPUT
203+
echo "SUBMODULES=$SUBMODULES" >> $GITHUB_OUTPUT
204+
echo "BRANCH=$BRANCH" >> $GITHUB_OUTPUT
205+
echo "SSH_USER=$SSH_USER" >> $GITHUB_OUTPUT
206+
echo "SSH_HOST=$SSH_HOST" >> $GITHUB_OUTPUT
207+
echo "SSH_PORT=$SSH_PORT" >> $GITHUB_OUTPUT
208+
echo "DEPLOY_SRC=$DEPLOY_SRC" >> $GITHUB_OUTPUT
209+
echo "DEPLOY_DST=$DEPLOY_DST" >> $GITHUB_OUTPUT
210+
echo "DEPLOY_NAME=$DEPLOY_NAME" >> $GITHUB_OUTPUT
211+
echo "RSYNC=$RSYNC" >> $GITHUB_OUTPUT
212+
echo "KEEP=$KEEP" >> $GITHUB_OUTPUT
213+
214+
ssh:
215+
runs-on: ubuntu-latest
216+
needs: [setup]
217+
if: ${{ inputs.SSH }}
218+
environment: ${{ inputs.ENVIRONMENT }}
219+
steps:
220+
- name: 🕵 Connect via SSH and create release directory
221+
run: |
222+
223+
# Setup SSH
224+
install -m 600 -D /dev/null ~/.ssh/id_rsa
225+
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
226+
echo "${{ vars.KNOWN_HOSTS }}" > ~/.ssh/known_hosts
227+
sshExec() {
228+
USER=${{ needs.setup.outputs.SSH_USER }}
229+
HOST=${{ needs.setup.outputs.SSH_HOST }}
230+
PORT=${{ needs.setup.outputs.SSH_PORT }}
231+
ssh $USER@$HOST -p$PORT "$@"
232+
}
233+
234+
# Check connection to the server
235+
sshExec "echo '✅ Connection successful'"
236+
237+
# Check if the deploy directory exists
238+
DST=${{ needs.setup.outputs.DEPLOY_DST }}
239+
sshExec \
240+
"if [ ! -d $DST ]; then
241+
echo '❌ Directory $DST does not exist - please create it'
242+
exit 1
243+
else
244+
echo '✅ Directory $DST exists'
245+
fi"
246+
247+
# Create the release directory
248+
NAME=${{ needs.setup.outputs.DEPLOY_NAME }}
249+
DIR=$DST/tmp-$NAME
250+
sshExec "mkdir -p $DIR"
251+
echo "✅ Release directory $DIR created"

0 commit comments

Comments
 (0)