From 5c30fa3cfaae2f2ce81d1b7488fd119288ee1294 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 18 Nov 2023 20:02:23 +0100 Subject: [PATCH] switch to gitea --- .gitea/workflows/action.yml | 103 ++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 70 ------------------------ 2 files changed, 103 insertions(+), 70 deletions(-) create mode 100644 .gitea/workflows/action.yml delete mode 100644 .gitlab-ci.yml diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml new file mode 100644 index 0000000..fbf348c --- /dev/null +++ b/.gitea/workflows/action.yml @@ -0,0 +1,103 @@ +name: CI/CD Pipeline + +on: + push: + branches: + - main + - staging + +env: + CARGO_TARGET: x86_64-unknown-linux-musl + SSH_HOST: ${{ secrets.SSH_HOST }} + SSH_USER: ${{ secrets.SSH_USER }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + +jobs: + build: + runs-on: ubuntu-latest + container: rust:latest + + steps: + - name: Setup Environment + run: | + rustup target add $CARGO_TARGET + apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y + + - name: Checkout + uses: actions/checkout@v3 + + - name: Run Test DB Script + run: ./test_db.sh + + - name: Build + run: | + cargo build --release --target $CARGO_TARGET + strip target/$CARGO_TARGET/release/rot + cd frontend && npm install && npm run build + + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: | + target/$CARGO_TARGET/release/rot + static + retention-days: 1 + + test: + runs-on: ubuntu-latest + container: rust:latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Run Tests + run: cargo test --verbose + + deploy-staging: + runs-on: ubuntu-latest + needs: [build, test] + if: github.ref == 'refs/heads/staging' + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Deploy to Staging + run: | + scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/rot-updating + scp staging-diff.sql $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ + scp -r static $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ + scp -r templates $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ + scp -r svelte $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ + ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rotstaging' + ssh $SSH_USER@$SSH_HOST 'rm /home/k004373/rowing-staging/db.sqlite && cp /home/k004373/rowing/db.sqlite /home/k004373/rowing-staging/db.sqlite && mkdir -p /home/k004373/rowing-staging/svelte/build && mkdir -p /home/k004373/rowing-staging/data-ergo/thirty && mkdir -p /home/k004373/rowing-staging/data-ergo/dozen && sqlite3 /home/k004373/rowing-staging/db.sqlite < /home/k004373/rowing-staging/staging-diff.sql' + ssh $SSH_USER@$SSH_HOST 'mv /home/k004373/rowing-staging/rot-updating /home/k004373/rowing-staging/rot' + ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rotstaging' + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + SSH_HOST: ${{ secrets.SSH_HOST }} + SSH_USER: ${{ secrets.SSH_USER }} + + deploy-main: + runs-on: ubuntu-latest + needs: [build, test] + if: github.ref == 'refs/heads/main' + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Deploy to Main + run: | + scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/k004373/rowing/rot-updating + scp -r static $SSH_USER@$SSH_HOST:/home/k004373/rowing/ + scp -r templates $SSH_USER@$SSH_HOST:/home/k004373/rowing/ + scp -r svelte $SSH_USER@$SSH_HOST:/home/k004373/rowing/ + ssh $SSH_USER@$SSH_HOST 'mkdir -p /home/k004373/rowing/svelte/build && mkdir -p /home/k004373/rowing/data-ergo/thirty && mkdir -p /home/k004373/rowing/data-ergo/dozen' + ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rot' + ssh $SSH_USER@$SSH_HOST 'mv /home/k004373/rowing/rot-updating /home/k004373/rowing/rot' + ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rot' + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + SSH_HOST: ${{ secrets.SSH_HOST }} + SSH_USER: ${{ secrets.SSH_USER }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 381c0a5..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,70 +0,0 @@ -image: rust:latest - -variables: - CARGO_TARGET: x86_64-unknown-linux-musl - -before_script: - - rustup target add $CARGO_TARGET - - apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y - - ./test_db.sh - -build: - stage: build - script: - - cargo build --release --target $CARGO_TARGET - - strip target/$CARGO_TARGET/release/rot - - cd frontend && npm install && npm run build - artifacts: - paths: - - target/$CARGO_TARGET/release/rot - - static - expire_in: 3 hours - -test: - stage: test - image: rust:latest - script: - - cargo test --verbose - -deploy-staging: - stage: deploy - before_script: - - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - - eval $(ssh-agent -s) - - echo "$SSH_PRIVATE_KEY" | ssh-add - - - mkdir -p ~/.ssh - - chmod 700 ~/.ssh - - ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts - script: - - scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/rot-updating - - scp staging-diff.sql $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ - - scp -r static $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ - - scp -r templates $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ - - scp -r svelte $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/ - - ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rotstaging' - - ssh $SSH_USER@$SSH_HOST 'rm /home/k004373/rowing-staging/db.sqlite && cp /home/k004373/rowing/db.sqlite /home/k004373/rowing-staging/db.sqlite && mkdir -p /home/k004373/rowing-staging/svelte/build && mkdir -p /home/k004373/rowing-staging/data-ergo/thirty && mkdir -p /home/k004373/rowing-staging/data-ergo/dozen && sqlite3 /home/k004373/rowing-staging/db.sqlite < /home/k004373/rowing-staging/staging-diff.sql' - - ssh $SSH_USER@$SSH_HOST 'mv /home/k004373/rowing-staging/rot-updating /home/k004373/rowing-staging/rot' - - ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rotstaging' - only: - - staging - -deploy-main: - stage: deploy - before_script: - - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - - eval $(ssh-agent -s) - - echo "$SSH_PRIVATE_KEY" | ssh-add - - - mkdir -p ~/.ssh - - chmod 700 ~/.ssh - - ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts - script: - - scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/k004373/rowing/rot-updating - - scp -r static $SSH_USER@$SSH_HOST:/home/k004373/rowing/ - - scp -r templates $SSH_USER@$SSH_HOST:/home/k004373/rowing/ - - scp -r svelte $SSH_USER@$SSH_HOST:/home/k004373/rowing/ - - ssh $SSH_USER@$SSH_HOST 'mkdir -p /home/k004373/rowing/svelte/build && mkdir -p /home/k004373/rowing/data-ergo/thirty && mkdir -p /home/k004373/rowing/data-ergo/dozen' - - ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rot' - - ssh $SSH_USER@$SSH_HOST 'mv /home/k004373/rowing/rot-updating /home/k004373/rowing/rot' - - ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rot' - only: - - main