-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (132 loc) · 6.01 KB
/
deploy.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
name: Deploy Pfaditechnik
on:
push:
branches:
- deploy
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: deploy
steps:
# Frontend deployment steps
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install frontend dependencies
run: npm install
- name: Build the frontend project
run: npm run docs:build
- name: Deploy frontend via SSH
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_SERVER: ${{ vars.SSH_SERVER }}
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H $SSH_SERVER >> ~/.ssh/known_hosts
cd .vitepress/dist
rsync -avz --delete . $SSH_USERNAME@$SSH_SERVER:$DEPLOY_PATH
- name: Ensure bootstrap/cache directory exists and is writable
run: |
mkdir -p ./api/bootstrap/cache
chmod -R 775 ./api/bootstrap/cache
- name: Install PHP 8.2 and Composer
run: |
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install -y php8.2 php8.2-cli php8.2-mbstring php8.2-xml php8.2-curl php8.2-zip php8.2-intl php8.2-bcmath unzip curl
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
- name: Install backend dependencies
run: composer install
working-directory: ./api
- name: Set up environment variables
env:
BACKEND_URL: ${{ secrets.BACKEND_URL }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_DATABASE: ${{ secrets.DB_DATABASE }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}
MAIL_MAILER: ${{ secrets.MAIL_MAILER }}
MAIL_HOST: ${{ secrets.MAIL_HOST }}
MAIL_PORT: ${{ secrets.MAIL_PORT }}
MAIL_ENCRYPTION: ${{ secrets.MAIL_ENCRYPTION }}
MAIL_FROM_ADDRESS: ${{ secrets.MAIL_FROM_ADDRESS }}
MAIL_FROM_NAME: ${{ secrets.MAIL_FROM_NAME }}
APP_KEY: ${{ secrets.APP_KEY }}
FRONTEND_URL: ${{ vars.FRONTEND_URL }}
CREDITOR_NAME: ${{ vars.CREDITOR_NAME }}
CREDITOR_STREET: ${{ vars.CREDITOR_STREET }}
CREDITOR_TOWN: ${{ vars.CREDITOR_TOWN }}
CREDITOR_ZIP: ${{ vars.CREDITOR_ZIP }}
CREDITOR_IBAN: ${{ vars.CREDITOR_IBAN }}
CREDITOR_EMAIL: ${{ vars.CREDITOR_EMAIL }}
run: |
cd ./api
rm -f .env
cp env.example .env
sed -ri "s~^APP_URL=.*$~APP_URL=$BACKEND_URL~" .env
sed -ri "s~^FRONTEND_URL=.*$~FRONTEND_URL=$FRONTEND_URL~" .env
sed -ri "s~^DB_HOST=.*$~DB_HOST=$DB_HOST~" .env
sed -ri "s~^DB_DATABASE=.*$~DB_DATABASE=$DB_DATABASE~" .env
sed -ri "s~^DB_USERNAME=.*$~DB_USERNAME=$DB_USERNAME~" .env
sed -ri "s~^DB_PASSWORD=.*$~DB_PASSWORD=$DB_PASSWORD~" .env
sed -ri "s~^MAIL_USERNAME=.*$~MAIL_USERNAME=$MAIL_USERNAME~" .env
sed -ri "s~^MAIL_PASSWORD=.*$~MAIL_PASSWORD=$MAIL_PASSWORD~" .env
sed -ri "s~^MAIL_MAILER=.*$~MAIL_MAILER=$MAIL_MAILER~" .env
sed -ri "s~^MAIL_HOST=.*$~MAIL_HOST=$MAIL_HOST~" .env
sed -ri "s~^MAIL_PORT=.*$~MAIL_PORT=$MAIL_PORT~" .env
sed -ri "s~^MAIL_ENCRYPTION=.*$~MAIL_ENCRYPTION=$MAIL_ENCRYPTION~" .env
sed -ri "s~^MAIL_FROM_ADDRESS=.*$~MAIL_FROM_ADDRESS=$MAIL_FROM_ADDRESS~" .env
sed -ri "s~^MAIL_FROM_NAME=.*\$~MAIL_FROM_NAME=\"$MAIL_FROM_NAME\"~" .env
sed -ri "s~^APP_KEY=.*$~APP_KEY=$APP_KEY~" .env
sed -ri "s~^CREDITOR_NAME=.*\$~CREDITOR_NAME=\"$CREDITOR_NAME\"~" .env
sed -ri "s~^CREDITOR_STREET=.*\$~CREDITOR_STREET=\"$CREDITOR_STREET\"~" .env
sed -ri "s~^CREDITOR_TOWN=.*\$~CREDITOR_TOWN=\"$CREDITOR_TOWN\"~" .env
sed -ri "s~^CREDITOR_ZIP=.*\$~CREDITOR_ZIP=\"$CREDITOR_ZIP\"~" .env
sed -ri "s~^CREDITOR_IBAN=.*\$~CREDITOR_IBAN=\"$CREDITOR_IBAN\"~" .env
sed -ri "s~^CREDITOR_EMAIL=.*\$~CREDITOR_EMAIL=\"$CREDITOR_EMAIL\"~" .env
- name: Deploy backend via SSH
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_SERVER: ${{ vars.SSH_SERVER }}
DEPLOY_PATH_BACKEND: ${{ vars.DEPLOY_PATH_BACKEND }}
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H $SSH_SERVER >> ~/.ssh/known_hosts
rsync -avz --delete ./api/ $SSH_USERNAME@$SSH_SERVER:$DEPLOY_PATH_BACKEND
- name: Set file permissions on the server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_SERVER: ${{ vars.SSH_SERVER }}
DEPLOY_PATH_BACKEND: ${{ vars.DEPLOY_PATH_BACKEND }}
run: |
ssh -i ~/.ssh/id_rsa $SSH_USERNAME@$SSH_SERVER "cd $DEPLOY_PATH_BACKEND && chmod -R 775 storage bootstrap/cache"
- name: Run migrations
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_SERVER: ${{ vars.SSH_SERVER }}
DEPLOY_PATH_BACKEND: ${{ vars.DEPLOY_PATH_BACKEND }}
run: |
ssh -i ~/.ssh/id_rsa $SSH_USERNAME@$SSH_SERVER "cd $DEPLOY_PATH_BACKEND && /usr/local/php83/bin/php artisan migrate --force"
- name: Optimize application
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_SERVER: ${{ vars.SSH_SERVER }}
DEPLOY_PATH_BACKEND: ${{ vars.DEPLOY_PATH_BACKEND }}
run: |
ssh -i ~/.ssh/id_rsa $SSH_USERNAME@$SSH_SERVER "cd $DEPLOY_PATH_BACKEND && /usr/local/php83/bin/php artisan config:cache && /usr/local/php83/bin/php artisan route:cache && /usr/local/php83/bin/php artisan view:cache"