wm-AllKids-tibi2023/.gitea/workflows/deploy.yaml

284 lines
11 KiB
YAML
Raw Normal View History

2023-09-17 13:24:39 +02:00
name: deploy to production
on: "push"
jobs:
2023-12-16 22:12:14 +01:00
lighthouse-evaluation:
runs-on: ubuntu-latest
container:
image: gitbase.de/actions/ubuntu:latest
volumes:
- /data:/data
2023-12-17 12:12:39 +01:00
services:
mongo:
image: mongo:4.2
ports:
- 27017:27017
options: --name mongo
2023-12-16 22:12:14 +01:00
2023-12-17 12:12:39 +01:00
maildev:
image: gitbase.de/robin/maildev:latest
ports:
- 80:80
- 25:25
options: --name maildev
2023-12-16 22:25:58 +01:00
2023-12-17 12:12:39 +01:00
tibi-server:
image: gitbase.de/cms/tibi-server
ports:
- 8080:8080
env:
DB_DIAL: mongodb://mongo
API_PORT: 8080
MAIL_HOST: maildev:25
SECURITY_ALLOWABSOLUTEPATHS: "true"
SECURITY_ALLOWUPPERPATHS: "true"
SECURITY_ALLOWRELATIVEPATHS: "true"
options: --name tibi-server
volumes:
- ${{ github.workspace }}:/repo
2023-12-16 22:25:58 +01:00
2023-12-17 12:12:39 +01:00
live-server:
image: gitbase.de/robin/apache-image:latest
2023-12-17 12:12:39 +01:00
ports:
- 8081:80
volumes:
- ${{ github.workspace }}/frontend:/usr/local/apache2/htdocs/
options: --name live-server
2023-12-24 10:46:36 +01:00
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: setup node 18
uses: actions/setup-node@v3
- name: Initialize database
uses: ./.github/actions/init-db
with:
TIBI_API_NAMESPACE: allkids_erfurt
TIBI_API_CONFIG_PATH: /repo/api/config.yml
PROJECT_NAME: AllKids
2023-12-24 10:46:36 +01:00
- name: SERVICE RESTART
uses: docker://docker
2023-12-24 10:46:36 +01:00
with:
args: docker restart live-server tibi-server mongo maildev
2023-12-24 10:46:36 +01:00
- name: Cache node modules
uses: actions/cache@v3
with:
path: |
.yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: setup yarn
2023-12-24 10:46:36 +01:00
run: |
corepack enable
corepack prepare yarn@3.2.4 --activate
yarn install
2023-12-24 10:46:36 +01:00
- name: modify config
run: |
sed -i 's#\(sentryEnvironment.*\)".*"#\1"${GITHUB_REF_NAME}"#g' frontend/src/config.ts
sed -i 's#//\( sentry\\.init.*\)#\1#g' frontend/src/config.ts
export $(cat .env | xargs)
echo "PROJECT_RELEASE=${RELEASE_PROJECT_SLUG}.r`git rev-list HEAD --count`-`git describe --all --long | sed 's+/+-+'`" >> .env
export $(cat .env | xargs)
echo ______ .env ______
cat .env
echo
sed -i 's#\(const release = \).*#\1"'${PROJECT_RELEASE}'"#g' api/hooks/config-client.js
# bash scripts/preload-meta.sh frontend/spa.html
# bash scripts/preload-meta.sh frontend/spa.html > frontend/_spa.html
# cp frontend/_spa.html frontend/spa.html
export stamp=`date +%s`
sed -i s/__TIMESTAMP__/$stamp/g frontend/spa.html
# sed -i s/__TIMESTAMP__/$stamp/g frontend/serviceworker.js
# cat frontend/serviceworker.js
# rm api/templates/spa.html
# cp frontend/spa.html api/templates/spa.html
echo ______ frontend/spa.html ______
cat frontend/spa.html
- name: build
env:
FORCE_COLOR: "true"
run: |
yarn build
- name: build ssr
2023-12-24 10:46:36 +01:00
env:
FORCE_COLOR: "true"
run: |
yarn build:server
#- name: Load .env file
# run: |
# set -a
# source .env
# set + a
- name: SERVICE RESTART
uses: docker://docker
with:
args: docker restart live-server tibi-server
- name: wait for boot
run: |
sleep 15
- name: Inspect Service Containers
run: |
for container_id in $(docker ps --format '{{.ID}}'); do
echo "::group:: Container logs:"
docker logs $container_id || true
echo "::endgroup::"
done
2023-12-26 13:45:24 +01:00
#- name: Wait for Live Server
# run: |
# attempts=0
# max_attempts=5
# same port since its inside the same network, so not 8081....
# while ! curl --fail "http://live-server:80"; do
# if [ $attempts -eq $max_attempts ]; then
# echo "Live server not ready after $max_attempts attempts"
# echo "${{ toJson(job) }}"
# curl -v "http://live-server:80" || true
# echo "::group::liveserver logs"
# docker logs live-server
# echo "::endgroup::"
# echo "::group:: tibi-server logs"
# docker logs tibi-server
# echo "::endgroup::"
# echo "::group:: tibi-server curl"
# docker exec live-server cat /var/log/apache2/access.log || true
# docker exec live-server bash -c "apt-get update && apt-get install -y curl"
# docker exec live-server echo $PATH
# docker exec live-server bash -c 'curl -v "http://tibi-server:8080/api/v1/_/allkids_erfurt/ssr?token=owshwerNwoa&url=/noindex"'
# echo "::endgroup::"
# exit 1
# fi
# attempts=$((attempts+1))
# echo "Waiting for live-server to be ready... attempt $attempts"
# sleep 5
# done
- name: Test HTTP Request
run: |
curl -v http://live-server:80
- name: Install Chrome
run: |
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install -y google-chrome-stable
# Lighthouse Analysis Step
- name: Lighthouse Analysis
run: |
yarn add lighthouse
2023-12-26 13:45:24 +01:00
npx lighthouse http://live-server:80 --output json --output-path /tmp/lighthouse-report.json --chrome-flags="--headless --no-sandbox --disable-dev-shm-usage"
2023-12-26 13:45:24 +01:00
- name: upload-to-nextcloud
run: |
2023-12-26 13:45:24 +01:00
sudo apt-get update && sudo apt-get install -y curl bash findutils
export datetime=`date +%Y-%m-%d_%H-%M-%S`
mkdir -p /tmp/cloudsend/${GITHUB_REF_NAME}/$${datetime}
mv /tmp/lighthouse-report.json /tmp/cloudsend/${GITHUB_REF_NAME}/$${datetime}/
./scripts/cloudsend.sh /tmp/cloudsend/ https://www.basiswolke.de/index.php/s/xHGsypbqiifnGH5
2023-12-16 22:23:08 +01:00
2023-09-17 13:24:39 +02:00
deploy:
name: deploy
runs-on: ubuntu-latest
container:
image: gitbase.de/actions/ubuntu:latest
volumes:
- /data:/data
2023-12-05 16:20:50 +01:00
2023-09-17 13:24:39 +02:00
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
2024-07-11 20:25:00 +02:00
lfs: true
submodules: true
2023-09-17 13:24:39 +02:00
2024-07-11 20:25:00 +02:00
- run: |
git fetch --force --tags
# setup node 20
- name: setup node 20
2023-09-17 13:24:39 +02:00
uses: actions/setup-node@v3
2024-07-11 20:25:00 +02:00
with:
node-version: 20
2023-09-17 13:24:39 +02:00
- name: install dependencies
run: |
2023-09-20 10:28:14 +02:00
npm install -g yarn
2023-09-17 13:24:39 +02:00
yarn install
- name: modify config
run: |
sed -i 's#\(sentryEnvironment.*\)".*"#\1"${GITHUB_REF_NAME}"#g' frontend/src/config.ts
sed -i 's#//\( sentry\\.init.*\)#\1#g' frontend/src/config.ts
2024-07-11 20:25:00 +02:00
set -o allexport
. ./.env
echo "PROJECT_RELEASE=${SENTRY_PROJECT}.r`git rev-list HEAD --count`-`git describe --all --long | sed 's+/+-+'`" >> .env
. ./.env
set +o allexport
2023-09-17 13:24:39 +02:00
echo ______ .env ______
cat .env
echo
sed -i 's#\(const release = \).*#\1"'${PROJECT_RELEASE}'"#g' api/hooks/config-client.js
2024-07-11 20:25:00 +02:00
sed -i 's#\(const originURL = \).*#\1"'${LIVE_URL}'"#g' api/hooks/config-client.js
2023-09-17 13:24:39 +02:00
# bash scripts/preload-meta.sh frontend/spa.html
# bash scripts/preload-meta.sh frontend/spa.html > frontend/_spa.html
# cp frontend/_spa.html frontend/spa.html
export stamp=`date +%s`
sed -i s/__TIMESTAMP__/$stamp/g frontend/spa.html
# sed -i s/__TIMESTAMP__/$stamp/g frontend/serviceworker.js
# cat frontend/serviceworker.js
2024-07-11 20:25:00 +02:00
rm api/templates/spa.html
cp frontend/spa.html api/templates/spa.html
2023-09-17 13:24:39 +02:00
echo ______ frontend/spa.html ______
cat frontend/spa.html
2023-12-05 22:30:23 +01:00
2024-07-11 20:25:00 +02:00
# sed -i 's#\(PREVIEW_URL=\).*#\1'${LIVE_URL}/preview'#g' api/config.yml.env
echo ______ api/config.yml.env ______
cat api/config.yml.env
2023-12-06 14:46:46 +01:00
- name: build
env:
FORCE_COLOR: "true"
run: |
yarn build
2023-12-06 18:57:25 +01:00
- name: build ssr
env:
FORCE_COLOR: "true"
run: |
yarn build:server
2023-12-06 14:46:46 +01:00
- name: build legacy
env:
FORCE_COLOR: "true"
run: |
yarn build:legacy
2023-09-17 13:24:39 +02:00
- name: deploy
if: github.ref == 'refs/heads/master'
env:
2023-09-20 10:41:20 +02:00
RSYNC_USER: "allkids_rsync_master"
2023-09-17 13:24:39 +02:00
RSYNC_PASS: ${{ secrets.rsync_master }}
run: |
scripts/deploy.sh ftp1.webmakers.de $RSYNC_USER $RSYNC_PASS