From 2acad7db6c9ab96ea06fed460e9219e22c67352a Mon Sep 17 00:00:00 2001 From: ndefokou Date: Mon, 18 Nov 2024 12:39:21 +0100 Subject: [PATCH] Adding CD workflow --- .github/workflows/rust.yml | 46 +++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fda6a064..cd39fc58 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,4 +1,4 @@ -name: Rust CI +name: Rust CI/CD on: push: @@ -12,8 +12,9 @@ env: CARGO_TERM_COLOR: always jobs: - build: - name: Build, Test, and Lint + # Continuous Integration Job + ci: + name: Continuous Integration runs-on: ubuntu-latest steps: @@ -45,13 +46,8 @@ jobs: - name: Create example env file run: | - if [ -f .github/scripts/test_config.sh ]; then - chmod +x .github/scripts/test_config.sh - sh .github/scripts/test_config.sh - else - echo "No test_config.sh script found, skipping..." - fi - + chmod +x .github/scripts/test_config.sh + sh .github/scripts/test_config.sh - name: Run Clippy (Lint) run: cargo clippy --workspace --all-targets --all-features -- -D warnings @@ -63,3 +59,33 @@ jobs: - name: Run Tests run: cargo nextest run --workspace --all-features + + # Continuous Deployment Job + cd: + name: Continuous Deployment + needs: ci + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + + - name: Build Release + run: cargo build --release --workspace --all-features + + - name: Deploy to Production + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + HOST: ${{ secrets.PRODUCTION_HOST }} + USER: ${{ secrets.PRODUCTION_USER }} + run: | + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ssh_key + chmod 600 ssh_key + scp -i ssh_key target/release/your_binary ${{ env.USER }}@${{ env.HOST }}:/path/to/your/binary + ssh -i ssh_key ${{ env.USER }}@${{ env.HOST }} 'systemctl restart your-service' + rm -f ssh_key