Dev pipeline und build Skript

This commit is contained in:
Moritz Utcke
2024-03-06 08:54:42 +07:00
parent 9964fded85
commit f679f215cc
4 changed files with 44 additions and 90 deletions

View File

@@ -1,20 +0,0 @@
name: Build and Test
on:
push:
branches: [ dev ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Build the application
uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
with:
bun-version: "latest"
- run: bun install
- run: bun run build
- run: bun run test:unit
- run: bun run test:e2e

View File

@@ -1,27 +1,26 @@
name: Dev Pipeline
on:
pull_request:
branches: [main]
push:
branches: [ dev ]
branches: [main]
jobs:
build:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy dev changes.
uses: appleboy/ssh-action@master
- uses: actions/checkout@v2
- uses: appleboy/ssh-action@master
with:
host: "212.227.155.91"
username: "root"
password: "!2Zc727cI1"
host: ${{ secrets.DEV_HOST }}
username: ${{ secrets.DEV_USERNAME }}
password: ${{ secrets.DEV_PASSWORD }}
port: 22
script: |
cd ~/apps/online-energieausweis
cd ~/online-energieausweis
git reset --hard HEAD
git clean -f -d
git pull origin main
git status
npm install -g bun
bun install
bash build.sh

View File

@@ -1,27 +0,0 @@
name: Production Deployment
on:
release:
types: [ created ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Deploy to production.
uses: appleboy/ssh-action@master
with:
host: "212.227.155.91"
username: "root"
password: "!2Zc727cI1"
port: 22
script: |
cd ~/apps/online-energieausweis
git reset --hard HEAD
git clean -f -d
git pull origin main
git status
npm install -g bun
bun install
bash build.sh

View File

@@ -9,38 +9,40 @@ DB_USER="main"
DB_PASSWORD="hHMP8cd^N3SnzGRR"
DB_PORT=5432
git_pull_force() {
git reset --hard HEAD
git clean -f -d
git pull origin main
}
# Wir gehen davon aus, dass die Änderungen bereits von GitHub gepullt wurden
# Dieses Skript ist nur dafür gedacht, von GitHub bei einer Automation
# ausgeführt zu werden. Außerdem würde es nicht wirklich Sinn ergeben, wenn das
# Build Skript sich die Änderungen am build Skript holen würde...
# Zuerst müssen wir neue Änderungen von GitHub pullen.
cd ~/apps/$APP_NAME
git_pull_force;
# Als erstes linken wir das package mit bun, damit wir z.B. in online-energieausweis darauf zugreifen können.
bun link
# Dann installieren wir noch einmal alle dependencies, das ist besonders wichtig
# falls wir lokal verlinkte Projekte haben, sonst werden die nicht in unser
# docker image übernommen
bun install
# Dann bauen wir das Docker Image unserer Application
cd ~/apps/$APP_NAME
# Dann stoppen wir unser altes docker image und bauen es neu.
docker stop $APP_NAME
docker rm $APP_NAME
docker build -t $APP_NAME .
# Wir legen ein persistent directory an
PERSISTENT_DIR="${HOME}/persistent/online-energieausweis";
# Jeder unserer Applikationen hat ein Verzeichnis in dem alle Dateien dauerhaft,
# Versionsunabhängig gespeichert werden. Dieses legen wir hier an, falls es noch
# nicht existiert.
PERSISTENT_DIR="${HOME}/persistent/${APP_NAME}";
mkdir -p $PERSISTENT_DIR;
# Wir legen einen .env file für unsere letsencrypt keys an.
rm -f ~/apps/$APP_NAME/.env;
touch ~/apps/$APP_NAME/.env;
echo "PRIVATE_KEY=$(cat /etc/letsencrypt/live/ibcornelsen.de/privkey.pem | base64 | tr -d '\n')" >> ~/apps/$APP_NAME/.env;
echo "CERTIFICATE=$(cat /etc/letsencrypt/live/ibcornelsen.de/fullchain.pem | base64 | tr -d '\n')" >> ~/apps/$APP_NAME/.env;
# TODO: Wir legen hier die .env Datei an, die die SSL Zertifikate enthält.
# rm -f ~/$APP_NAME/.env;
# touch ~/$APP_NAME/.env;
# echo "PRIVATE_KEY=$(cat /etc/letsencrypt/live/ibcornelsen.de/privkey.pem | base64 | tr -d '\n')" >> ~/$APP_NAME/.env;
# echo "CERTIFICATE=$(cat /etc/letsencrypt/live/ibcornelsen.de/fullchain.pem | base64 | tr -d '\n')" >> ~/$APP_NAME/.env;
# Und starten unsere App wieder.
# Jetzt wo wir alle Vorbereitungen getroffen haben, starten wir das Docker Image und linken es mit der Datenbank.
docker run -d --name $APP_NAME --link $DB_CONTAINER_NAME \
-v "${PERSISTENT_DIR}:/persistent" \
-p "${APP_PORT}:80" \
-v "./node_modules/@ibcornelsen/database:/${APP_NAME}/node_modules/@ibcornelsen/database" \
-v "./node_modules/@ibcornelsen/api:/${APP_NAME}/node_modules/@ibcornelsen/api" \
-v "./node_modules/@ibcornelsen/ui:/${APP_NAME}/node_modules/@ibcornelsen/ui" \
-p "${APP_PORT}:3000" \
$APP_NAME;
# Crontab Updaten
cd ~/$APP_NAME
crontab .crontab