diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7a5fc03..12551ae 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,17 +6,30 @@ on: tags: [v*] jobs: + prepare-matrix: + name: Prepare Matrix Output + runs-on: ubuntu-latest + outputs: + servers: ${{ steps.create-matrix.outputs.matrix }} + steps: + - name: Create Matrix Variable + id: create-matrix + run: echo "matrix=$(jq -cr '@json' <<< "${{ vars.SSH_SERVER_LIST }}")" >> $GITHUB_OUTPUT + deploy: name: Deploy runs-on: ubuntu-latest + needs: [prepare-matrix] + strategy: + matrix: + server: ${{ fromJSON(needs.prepare-matrix.outputs.servers) }} steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Deploy the latest version + - name: Deploy to ${{ matrix.server.name }} env: - SSH_SERVER_LIST: ${{ vars.SSH_SERVER_LIST }} SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} run: | if [ -z "$SSH_PRIVATE_KEY" ]; then @@ -24,23 +37,14 @@ jobs: exit 1 fi - if [ -z "$SSH_SERVER_LIST" ]; then - echo "SSH_SERVER_LIST is not set" - exit 1 - fi - # Save the private key to a file mkdir -p $HOME/.ssh echo "$SSH_PRIVATE_KEY" > $HOME/.ssh/id_ed25519 chmod 600 $HOME/.ssh/id_ed25519 - # Split SSH_SERVER_LIST by comma - IFS=',' read -ra SERVER_LIST <<< "$SSH_SERVER_LIST" - for server in "${SERVER_LIST[@]}"; do - ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no "$server" "mkdir -p /opt/estkme-cloud" - scp -i $HOME/.ssh/id_ed25519 -r scripts/deploy.sh $server:/opt/estkme-cloud - ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no $server "sudo /opt/estkme-cloud/deploy.sh && rm -f /opt/estkme-cloud/deploy.sh" - done + ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ matrix.server.user }}@${{ matrix.server.host }} -p ${{ matrix.server.port }} "mkdir -p /opt/estkme-cloud" + scp -i $HOME/.ssh/id_ed25519 -r scripts/deploy.sh -P ${{ matrix.server.port }} ${{ matrix.server.user }}@${{ matrix.server.host }}:/opt/estkme-cloud + ssh -i $HOME/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ matrix.server.user }}@${{ matrix.server.host }} -p ${{ matrix.server.port }} "sudo /opt/estkme-cloud/deploy.sh && rm -f /opt/estkme-cloud/deploy.sh"