Compare commits
5
Commits
main
..
e09f248256
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e09f248256 | ||
|
|
850d1be725 | ||
|
|
3981773ed8 | ||
|
|
d4b8a721d6 | ||
|
|
7ba8935999 |
@@ -4,21 +4,15 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request_target:
|
||||||
types: [opened, synchronize, reopened, closed]
|
types: [opened, synchronize, reopened, closed]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Base path for PR preview environments
|
REMOTE_DEPLOY_PATH: /tmp/app # Change to your remote deploy base path
|
||||||
REMOTE_DEPLOY_PATH: /var/app/test/test
|
|
||||||
|
|
||||||
# --- CUSTOMIZABLE PRODUCTION PATH ---
|
|
||||||
# Set the absolute path for your production deployment on the remote server.
|
|
||||||
REMOTE_PROD_PATH: /var/app/test/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 }}
|
SSH_PORT: ${{ secrets.SSH_PORT || 22 }} # Default to port 22 if not set
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
prepare_deployment_vars:
|
prepare_deployment_vars:
|
||||||
@@ -30,18 +24,14 @@ 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
|
||||||
# For PRs, create a unique directory under the base path
|
DEPLOY_DIR_NAME="pr-${{ github.event.pull_request.number }}"
|
||||||
DEPLOY_PATH="${REMOTE_DEPLOY_PATH}/${REPO_NAME}-pr-${{ github.event.pull_request.number }}"
|
|
||||||
else
|
else
|
||||||
# For 'main' branch, use the specified production path.
|
DEPLOY_DIR_NAME="main"
|
||||||
# Fallback to a default if REMOTE_PROD_PATH is empty.
|
|
||||||
DEPLOY_PATH="${REMOTE_PROD_PATH:-${REMOTE_DEPLOY_PATH}/main}"
|
|
||||||
fi
|
fi
|
||||||
echo "DEPLOY_PATH=${DEPLOY_PATH}" >> $GITHUB_ENV
|
echo "DEPLOY_PATH=${REMOTE_DEPLOY_PATH}/${DEPLOY_DIR_NAME}" >> $GITHUB_ENV
|
||||||
echo "deploy_path=${DEPLOY_PATH}" >> $GITHUB_OUTPUT
|
echo "deploy_path=${REMOTE_DEPLOY_PATH}/${DEPLOY_DIR_NAME}" >> $GITHUB_OUTPUT
|
||||||
echo "DEPLOY_PATH will be: ${DEPLOY_PATH}"
|
echo "DEPLOY_PATH will be: ${REMOTE_DEPLOY_PATH}/${DEPLOY_DIR_NAME}"
|
||||||
|
|
||||||
create_remote_directory:
|
create_remote_directory:
|
||||||
name: Create remote directory
|
name: Create remote directory
|
||||||
@@ -52,7 +42,7 @@ jobs:
|
|||||||
|| github.ref == 'refs/heads/main'
|
|| github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- name: Setup SSH
|
- name: Setup SSH
|
||||||
uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0
|
uses: webfactory/ssh-agent@v0.9.0
|
||||||
with:
|
with:
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
@@ -60,6 +50,7 @@ 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
|
||||||
@@ -67,7 +58,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
|
||||||
@@ -77,11 +68,10 @@ jobs:
|
|||||||
(github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged == false)
|
(github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged == false)
|
||||||
|| github.ref == 'refs/heads/main'
|
|| github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
|
|
||||||
- name: Sync files via scp
|
- name: Sync files via scp
|
||||||
uses: appleboy/scp-action@7e85c2e09aa21988492acd66466b5d68bda49e2b # master
|
uses: appleboy/scp-action@master
|
||||||
with:
|
with:
|
||||||
host: ${{ env.SSH_HOST }}
|
host: ${{ env.SSH_HOST }}
|
||||||
username: ${{ env.SSH_USER }}
|
username: ${{ env.SSH_USER }}
|
||||||
@@ -89,6 +79,12 @@ 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
|
||||||
@@ -99,7 +95,7 @@ jobs:
|
|||||||
|| github.ref == 'refs/heads/main'
|
|| github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- name: Setup SSH
|
- name: Setup SSH
|
||||||
uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0
|
uses: webfactory/ssh-agent@v0.9.0
|
||||||
with:
|
with:
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
@@ -107,6 +103,7 @@ 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
|
||||||
@@ -114,18 +111,18 @@ 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
|
needs: [prepare_deployment_vars, 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)
|
||||||
steps:
|
steps:
|
||||||
- name: Setup SSH
|
- name: Setup SSH
|
||||||
uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0
|
uses: webfactory/ssh-agent@v0.9.0
|
||||||
with:
|
with:
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
@@ -133,15 +130,13 @@ 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
|
||||||
}
|
}
|
||||||
chmod 644 ~/.ssh/known_hosts
|
chmod 644 ~/.ssh/known_hosts
|
||||||
|
|
||||||
- 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"
|
|
||||||
|
|
||||||
- name: Delete deployment directory
|
- name: Delete deployment directory
|
||||||
run: |
|
run: |
|
||||||
ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "if [ -d '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' ]; then rm -rf '${{ needs.prepare_deployment_vars.outputs.deploy_path }}'; echo 'Directory removed.'; else echo 'Directory not found, skipping.'; fi"
|
ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "if [ -d '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' ]; then rm -rf '${{ needs.prepare_deployment_vars.outputs.deploy_path }}'; echo 'Directory removed.'; else echo 'Directory not found, skipping.'; fi"
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
version: "3.9"
|
version: "3.9"
|
||||||
services:
|
services:
|
||||||
web:
|
web:
|
||||||
image: nginx:1.31.6-alpine-slim@sha256:80149a0e5bc9fa0b8beaff5b8a453f71ba8ba038895d418381297ffa5cd57782
|
image: nginx:1.26.1-alpine3.19-slim
|
||||||
ports:
|
ports:
|
||||||
- "80"
|
- "81"
|
||||||
volumes:
|
volumes:
|
||||||
- ./html:/usr/share/nginx/html:ro
|
- ./html:/usr/share/nginx/html:ro
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Sziasztok, emberek! 👋</h1>
|
<h1>Sziasztok, emberek! 👋</h1>
|
||||||
<h2>Másik szöveg</h2>
|
<h2>Másik szöveg</h2>
|
||||||
|
<h3>Harmadik szöveg</h3>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
+1
-10
@@ -2,14 +2,5 @@
|
|||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"extends": [
|
"extends": [
|
||||||
"config:recommended"
|
"config:recommended"
|
||||||
],
|
]
|
||||||
// "packageRules": [
|
|
||||||
// {
|
|
||||||
// "matchCategories": [
|
|
||||||
// "docker"
|
|
||||||
// ],
|
|
||||||
// "pinDigests": true
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
"pinDigests": true
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user