clean CI
This commit is contained in:
35
.github/workflows/deploy.yml
vendored
35
.github/workflows/deploy.yml
vendored
@@ -1,35 +0,0 @@
|
||||
name: Deploy App
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
container:
|
||||
volumes:
|
||||
- /var/docker-web:/var/docker-web
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Prepare and build app
|
||||
run: |
|
||||
REPO_NAME="${GITHUB_REPOSITORY##*/}"
|
||||
APP_DIR="/var/docker-web/apps/${REPO_NAME}"
|
||||
bash /var/docker-web/src/cli.sh down "${REPO_NAME}"
|
||||
rm -rf "$APP_DIR"
|
||||
mkdir "$APP_DIR"
|
||||
cp -a $(find . -mindepth 1 -maxdepth 1 ! -name '.git' ! -name 'node_modules') "$APP_DIR/"
|
||||
export COMPOSE_BAKE=false
|
||||
docker rmi "local/${REPO_NAME}" 2>/dev/null || true
|
||||
bash /var/docker-web/src/cli.sh build "${REPO_NAME}"
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-22.04
|
||||
needs: build
|
||||
container:
|
||||
volumes:
|
||||
- /var/docker-web:/var/docker-web
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Deploy with docker-web
|
||||
run: |
|
||||
REPO_NAME="${GITHUB_REPOSITORY##*/}"
|
||||
bash /var/docker-web/src/cli.sh up "${REPO_NAME}"
|
||||
23
.github/workflows/merge.yml
vendored
Normal file
23
.github/workflows/merge.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
name: Delete Merged Branches
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
|
||||
jobs:
|
||||
delete-branch:
|
||||
runs-on: ubuntu-22.04
|
||||
container:
|
||||
volumes:
|
||||
- /var/docker-web:/var/docker-web
|
||||
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Delete merged branch
|
||||
run: |
|
||||
BRANCH_NAME="${{ github.event.pull_request.head.ref || github.event.inputs.branch_name }}"
|
||||
APP_NAME="${BRANCH_NAME}_${GITHUB_REPOSITORY##*/}"
|
||||
if [ "$BRANCH_NAME" != "main" ] && [ "$BRANCH_NAME" != "develop" ] && [ -n "$APP_NAME" ]; then
|
||||
bash /var/docker-web/src/cli.sh rm -y "${APP_NAME}"
|
||||
else
|
||||
echo "Cannot delete protected branch: $BRANCH_NAME"
|
||||
fi
|
||||
41
.github/workflows/push.yml
vendored
Normal file
41
.github/workflows/push.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
name: Deploy App
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
container:
|
||||
volumes:
|
||||
- /var/docker-web:/var/docker-web
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build app
|
||||
run: |
|
||||
bash ./.github/workflows/setup-env.sh
|
||||
set -a && source .env && set +a
|
||||
if [ -n "$APP_NAME" ]; then
|
||||
set -a && source .env && set +a
|
||||
bash /var/docker-web/src/cli.sh down "${APP_NAME}"
|
||||
rm -rf "$APP_DIR"
|
||||
mkdir "$APP_DIR"
|
||||
cp -a $(find . -mindepth 1 -maxdepth 1 ! -name '.git' ! -name 'node_modules') "$APP_DIR/"
|
||||
export COMPOSE_BAKE=false
|
||||
docker rmi "local/${APP_NAME}" 2>/dev/null || true
|
||||
bash /var/docker-web/src/cli.sh build "${APP_NAME}"
|
||||
fi
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-22.04
|
||||
needs: build
|
||||
container:
|
||||
volumes:
|
||||
- /var/docker-web:/var/docker-web
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Deploy
|
||||
run: |
|
||||
bash ./.github/workflows/setup-env.sh
|
||||
set -a && source .env && set +a
|
||||
if [ -n "$APP_NAME" ]; then
|
||||
bash /var/docker-web/src/cli.sh up "${APP_NAME}"
|
||||
fi
|
||||
34
.github/workflows/setup-env.sh
vendored
Normal file
34
.github/workflows/setup-env.sh
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -a && source .env && set +a
|
||||
|
||||
changeEnvVar() {
|
||||
local var_name="$1"
|
||||
local new_value="$2"
|
||||
local env_file=".env"
|
||||
|
||||
if grep -q "^${var_name}=" "$env_file"; then
|
||||
sed -i "s|${var_name}=.*|${var_name}=${new_value}|" "$env_file"
|
||||
else
|
||||
echo "${var_name}=${new_value}" >> "$env_file"
|
||||
fi
|
||||
}
|
||||
|
||||
# Variables GitHub
|
||||
APP_NAME="${GITHUB_REPOSITORY##*/}"
|
||||
BRANCH_NAME=$GITHUB_REF_NAME
|
||||
|
||||
# Configuration pour les branches non-principales
|
||||
if [ "$BRANCH_NAME" != "main" ] && [ "$BRANCH_NAME" != "master" ]; then
|
||||
DOMAIN="$BRANCH_NAME.$DOMAIN"
|
||||
APP_NAME="${BRANCH_NAME}_${APP_NAME}"
|
||||
PORT=$(bash /var/docker-web/src/cli.sh ALLOCATE_PORT)
|
||||
sed -i "s|${GITHUB_REPOSITORY##*/}|$APP_NAME|g" docker-compose.yml
|
||||
fi
|
||||
|
||||
APP_DIR="/var/docker-web/apps/$APP_NAME"
|
||||
|
||||
changeEnvVar "DOMAIN" $DOMAIN
|
||||
changeEnvVar "APP_NAME" $APP_NAME
|
||||
changeEnvVar "PORT" $PORT
|
||||
changeEnvVar "APP_DIR" $APP_DIR
|
||||
Reference in New Issue
Block a user