diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index 32f69c1..fbb58b7 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -90,13 +90,12 @@ jobs: source: "./" target: "${{ needs.prepare_deployment_vars.outputs.deploy_path }}" - run_docker_compose: - name: Run docker-compose remotely + run_docker_compose_dev: + name: Run docker-compose remotely (Dev) runs-on: ubuntu-latest needs: [sync_repo_files, prepare_deployment_vars] if: | - (github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged == false) - || github.ref == 'refs/heads/main' + (github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged == false)' steps: - name: Setup SSH uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd # v0.9.1 @@ -114,7 +113,31 @@ jobs: chmod 644 ~/.ssh/known_hosts - 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 -f docker-compose.yaml -f docker-compose-pr.yaml up -d --build" + run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' && docker-compose --env-file dev.env -f docker-compose.yaml up -d --build" + run_docker_compose_prod: + name: Run docker-compose remotely (Prod) + runs-on: ubuntu-latest + needs: [sync_repo_files, prepare_deployment_vars] + if: | + (github.ref == 'refs/heads/main') + steps: + - name: Setup SSH + uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd # v0.9.1 + with: + ssh-private-key: ${{ env.SSH_PRIVATE_KEY }} + + - name: Add host to known_hosts + run: | + mkdir -p ~/.ssh + chmod 700 ~/.ssh + 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" + exit 1 + } + chmod 644 ~/.ssh/known_hosts + + - 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 --env-file prod.env -f docker-compose.yaml up -d --build" cleanup_mr_environment: name: Cleanup MR environment diff --git a/dev.env b/dev.env new file mode 100644 index 0000000..3ec5165 --- /dev/null +++ b/dev.env @@ -0,0 +1,3 @@ +PORT=898 +ENV=dev +NETWORK_NAME=proxy \ No newline at end of file diff --git a/docker-compose-pr.yaml b/docker-compose-pr.yaml deleted file mode 100644 index 2d739ba..0000000 --- a/docker-compose-pr.yaml +++ /dev/null @@ -1,5 +0,0 @@ -services: - traefik: - ports: !override - - "8001:80" - - "12473:8080" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index a51a59d..3ab34ee 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,11 +11,11 @@ services: - "--providers.docker=true" - "--providers.docker.exposedbydefault=false" - "--providers.docker.network=testnetwork" - - "--providers.docker.constraints=Label(`env`, `pr`)" + - "--providers.docker.constraints=Label(`env`, `${ENV}`)" - "--entryPoints.test.address=:80" ports: - - "80:80" - - "8080:8080" + - "${PORT}:80" + - "8080" volumes: - "/var/run/docker.sock:/var/run/docker.sock:ro" @@ -25,7 +25,7 @@ services: networks: - testnetwork labels: - - "env=pr" + - "env=${ENV}" - "traefik.enable=true" - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)" - "traefik.http.routers.whoami.entrypoints=test" @@ -37,7 +37,7 @@ services: ports: - "80" labels: - - "env=pr" + - "env=${ENV}" - "traefik.enable=true" - "traefik.http.routers.test.rule=Host(`test.docker.localhost`)" - "traefik.http.routers.test.entrypoints=test" diff --git a/prod.env b/prod.env new file mode 100644 index 0000000..48065d2 --- /dev/null +++ b/prod.env @@ -0,0 +1,3 @@ +PORT=80 +ENV=prod +NETWORK_NAME=proxy \ No newline at end of file