diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 229eb78..13866f2 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -209,14 +209,29 @@ jobs: exit 1 fi - # Run the simplified deployment script - echo "Executing zero-downtime deployment..." - if ./scripts/deploy.sh --version "${{secrets.PACKAGE_VERSION}}"; then - echo "โœ… Deployment successful" - else - echo "โŒ Deployment failed - automatic rollback should have occurred" - exit 1 - fi + # Navigate to the executeme directory on the VPS. + cd ~/${{secrets.PACKAGE_NAME}} + + # make sure we are in executeme directory + ls -a + + # Pull the latest code from the 'main' branch of the GitHub repository. + git pull origin main + + # Check git status to make sure everything is up to date + # git status + + # Execute your bash script. + bash ./scripts/simple-deploy.sh + + # # Run the simplified deployment script + # echo "Executing zero-downtime deployment..." + # if ./scripts/deploy.sh --version "${{secrets.PACKAGE_VERSION}}"; then + # echo "โœ… Deployment successful" + # else + # echo "โŒ Deployment failed - automatic rollback should have occurred" + # exit 1 + # fi # Cleanup docker logout @@ -225,29 +240,29 @@ jobs: echo "๐ŸŽ‰ DEPLOYMENT COMPLETED SUCCESSFULLY!" DEPLOY_EOF - - name: Verify Deployment โœ… - run: | - echo "Verifying deployment..." - ssh deploy-server bash << 'VERIFY_EOF' - cd ~/${{secrets.PACKAGE_NAME}} - - echo "=== Running deployment status check ===" - ./scripts/deploy.sh status - - echo "=== Testing endpoint directly ===" - if curl -f -s --connect-timeout 5 --max-time 10 "http://localhost:${{secrets.PORT}}/" | grep -q '"status":"ok"'; then - echo "๐ŸŽ‰ Endpoint health check passed! Service is responding with status: ok" - else - echo "โŒ Endpoint health check failed!" - exit 1 - fi - - echo "=== Final verification ===" - echo "Deployment verified successfully!" - VERIFY_EOF - - - name: Cleanup ๐Ÿงน - if: always() - run: | - rm -rf ~/.ssh/deploy_key* ~/.ssh/config - rm -f .env + # - name: Verify Deployment โœ… + # run: | + # echo "Verifying deployment..." + # ssh deploy-server bash << 'VERIFY_EOF' + # cd ~/${{secrets.PACKAGE_NAME}} + + # echo "=== Running deployment status check ===" + # ./scripts/deploy.sh status + + # echo "=== Testing endpoint directly ===" + # if curl -f -s --connect-timeout 5 --max-time 10 "http://localhost:${{secrets.PORT}}/" | grep -q '"status":"ok"'; then + # echo "๐ŸŽ‰ Endpoint health check passed! Service is responding with status: ok" + # else + # echo "โŒ Endpoint health check failed!" + # exit 1 + # fi + + # echo "=== Final verification ===" + # echo "Deployment verified successfully!" + # VERIFY_EOF + + # - name: Cleanup ๐Ÿงน + # if: always() + # run: | + # rm -rf ~/.ssh/deploy_key* ~/.ssh/config + # rm -f .env diff --git a/.github/workflows/nginx-setup.yml b/.github/workflows/nginx-setup.yml new file mode 100644 index 0000000..2737e32 --- /dev/null +++ b/.github/workflows/nginx-setup.yml @@ -0,0 +1,92 @@ +name: ๐Ÿš€ Deploy NGINX HTTPS Reverse Proxy ๐Ÿ” + +on: + workflow_run: + workflows: ["Deployment VPS"] + types: + - completed + +jobs: + deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} + runs-on: ubuntu-latest + + steps: + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v3 + + - name: ๐Ÿ”ง Setup and load environment + uses: ./.github/actions/setup-and-load-env + with: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + PACKAGE_NAME: ${{ secrets.PACKAGE_NAME }} + PACKAGE_VERSION: ${{ secrets.PACKAGE_VERSION }} + EMAIL: ${{ secrets.EMAIL }} + BASE_URL: ${{ secrets.BASE_URL }} + PORT: ${{ secrets.PORT }} + IMAGE_TAG: ${{ secrets.IMAGE_TAG }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + GIT_TOKEN: ${{ secrets.EXECUTE_ME_GITHUB_TOKEN }} + VPS_HOST: ${{ secrets.VPS_HOST }} + VPS_USER: ${{ secrets.VPS_USER }} + VPS_SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PRIVATE_KEY }} + + - name: ๐Ÿ“‹ Verify environment variables + run: | + echo "Package name: $PACKAGE_NAME" + echo "Package version: $PACKAGE_VERSION" + echo "Docker image: $IMAGE_TAG" + echo "โœ… Environment variables are accessible" + + - name: ๐Ÿ” Setup SSH + run: | + mkdir -p ~/.ssh + chmod 700 ~/.ssh + echo "${{secrets.VPS_SSH_PRIVATE_KEY}}" | tr -d '\r' > ~/.ssh/deploy_key + chmod 600 ~/.ssh/deploy_key + ssh-keyscan -H ${{secrets.VPS_HOST}} >> ~/.ssh/known_hosts + + cat > ~/.ssh/config << EOF + Host deploy-server + HostName ${{secrets.VPS_HOST}} + User ${{secrets.VPS_USER}} + IdentityFile ~/.ssh/deploy_key + StrictHostKeyChecking no + EOF + chmod 600 ~/.ssh/config + + - name: ๐Ÿš€ Test SSH Connection + run: ssh deploy-server "echo 'โœ… SSH connection successful'" + + - name: ๐Ÿ“ Debug scripts directory + run: ls -al ./scripts + + - name: ๐Ÿงช Run NGINX Setup Script on VPS + run: | + echo "๐Ÿš€ Preparing to run setup-nginx.sh on VPS" + + ssh deploy-server "bash -s" <