Compare commits

...

2 Commits

Author SHA1 Message Date
c2bd6da20e Merge pull request 'Improved pipeline' (#11) from improve-pipeline into main
All checks were successful
Remote Deployment Pipeline / Prepare deployment vars (push) Successful in 2s
Remote Deployment Pipeline / Create remote directory (push) Successful in 6s
Remote Deployment Pipeline / Cleanup MR environment (push) Has been skipped
Remote Deployment Pipeline / Sync repository files (push) Successful in 16s
Remote Deployment Pipeline / Run docker-compose remotely (push) Successful in 8s
Reviewed-on: #11
2025-10-26 20:41:14 +01:00
kovagoadi
a309f7664a Improved pipeline
All checks were successful
Remote Deployment Pipeline / Prepare deployment vars (pull_request) Successful in 2s
Remote Deployment Pipeline / Create remote directory (pull_request) Has been skipped
Remote Deployment Pipeline / Cleanup MR environment (pull_request) Successful in 8s
Remote Deployment Pipeline / Sync repository files (pull_request) Has been skipped
Remote Deployment Pipeline / Run docker-compose remotely (pull_request) Has been skipped
2025-10-26 20:38:38 +01:00

View File

@@ -8,11 +8,17 @@ on:
types: [opened, synchronize, reopened, closed] types: [opened, synchronize, reopened, closed]
env: env:
REMOTE_DEPLOY_PATH: /tmp/app # Change to your remote deploy base path # Base path for PR preview environments
REMOTE_DEPLOY_PATH: /var/app/test
# --- CUSTOMIZABLE PRODUCTION PATH ---
# Set the absolute path for your production deployment on the remote server.
REMOTE_PROD_PATH: /var/app/test/prod
SSH_HOST: ${{ secrets.SSH_HOST }} SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }} SSH_USER: ${{ secrets.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_PORT: ${{ secrets.SSH_PORT || 22 }} # Default to port 22 if not set SSH_PORT: ${{ secrets.SSH_PORT || 22 }}
jobs: jobs:
prepare_deployment_vars: prepare_deployment_vars:
@@ -24,14 +30,18 @@ jobs:
- name: Set deployment variables - name: Set deployment variables
id: set-vars id: set-vars
run: | run: |
REPO_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
if [[ "${{ github.event_name }}" == "pull_request" ]]; then if [[ "${{ github.event_name }}" == "pull_request" ]]; then
DEPLOY_DIR_NAME="pr-${{ github.event.pull_request.number }}" # For PRs, create a unique directory under the base path
DEPLOY_PATH="${REMOTE_DEPLOY_PATH}/${REPO_NAME}-pr-${{ github.event.pull_request.number }}"
else else
DEPLOY_DIR_NAME="main" # For 'main' branch, use the specified production path.
# Fallback to a default if REMOTE_PROD_PATH is empty.
DEPLOY_PATH="${REMOTE_PROD_PATH:-${REMOTE_DEPLOY_PATH}/main}"
fi fi
echo "DEPLOY_PATH=${REMOTE_DEPLOY_PATH}/${DEPLOY_DIR_NAME}" >> $GITHUB_ENV echo "DEPLOY_PATH=${DEPLOY_PATH}" >> $GITHUB_ENV
echo "deploy_path=${REMOTE_DEPLOY_PATH}/${DEPLOY_DIR_NAME}" >> $GITHUB_OUTPUT echo "deploy_path=${DEPLOY_PATH}" >> $GITHUB_OUTPUT
echo "DEPLOY_PATH will be: ${REMOTE_DEPLOY_PATH}/${DEPLOY_DIR_NAME}" echo "DEPLOY_PATH will be: ${DEPLOY_PATH}"
create_remote_directory: create_remote_directory:
name: Create remote directory name: Create remote directory
@@ -50,7 +60,6 @@ jobs:
run: | run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
chmod 700 ~/.ssh chmod 700 ~/.ssh
echo "Scanning SSH host key for $SSH_HOST:$SSH_PORT..."
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || { ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT" echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
exit 1 exit 1
@@ -58,7 +67,7 @@ jobs:
chmod 644 ~/.ssh/known_hosts chmod 644 ~/.ssh/known_hosts
- name: Create directory on remote - name: Create directory on remote
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "mkdir -p ${{ needs.prepare_deployment_vars.outputs.deploy_path }}" run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "mkdir -p '${{ needs.prepare_deployment_vars.outputs.deploy_path }}'"
sync_repo_files: sync_repo_files:
name: Sync repository files name: Sync repository files
@@ -79,12 +88,6 @@ jobs:
port: ${{ env.SSH_PORT }} port: ${{ env.SSH_PORT }}
source: "./" source: "./"
target: "${{ needs.prepare_deployment_vars.outputs.deploy_path }}" target: "${{ needs.prepare_deployment_vars.outputs.deploy_path }}"
#target: "/tmp/app/main"
# The 'exclude' parameter is supported and should be kept
# exclude: |
# .git/
# .github/
# node_modules/
run_docker_compose: run_docker_compose:
name: Run docker-compose remotely name: Run docker-compose remotely
@@ -103,7 +106,6 @@ jobs:
run: | run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
chmod 700 ~/.ssh chmod 700 ~/.ssh
echo "Scanning SSH host key for $SSH_HOST:$SSH_PORT..."
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || { ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT" echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
exit 1 exit 1
@@ -111,12 +113,12 @@ jobs:
chmod 644 ~/.ssh/known_hosts chmod 644 ~/.ssh/known_hosts
- name: Run docker-compose on remote host - name: Run docker-compose on remote host
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd ${{ needs.prepare_deployment_vars.outputs.deploy_path }} && docker-compose up -d --build" run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' && docker-compose up -d --build"
cleanup_mr_environment: cleanup_mr_environment:
name: Cleanup MR environment name: Cleanup MR environment
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [prepare_deployment_vars, prepare_deployment_vars] needs: prepare_deployment_vars
if: | if: |
github.event_name == 'pull_request' && github.event_name == 'pull_request' &&
(github.event.action == 'closed' || github.event.pull_request.merged == true) (github.event.action == 'closed' || github.event.pull_request.merged == true)
@@ -130,7 +132,6 @@ jobs:
run: | run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
chmod 700 ~/.ssh chmod 700 ~/.ssh
echo "Scanning SSH host key for $SSH_HOST:$SSH_PORT..."
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || { ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT" echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
exit 1 exit 1
@@ -138,7 +139,7 @@ jobs:
chmod 644 ~/.ssh/known_hosts chmod 644 ~/.ssh/known_hosts
- name: Run docker-compose down on remote host - name: Run docker-compose down on remote host
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd ${{ needs.prepare_deployment_vars.outputs.deploy_path }} && docker-compose down" run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' && docker-compose down"
- name: Delete deployment directory - name: Delete deployment directory
run: | run: |