diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 117495d..9937590 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,4 +1,4 @@ -name: Node.js CI +name: Node.js CI/CD on: push: @@ -14,17 +14,25 @@ jobs: matrix: node-version: [18.x] steps: - - uses: actions/checkout@v3 + - name: Checkout Repository + uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm ci - - run: npm run build + - name: Install Dependencies and Build + run: | + npm ci + npm run build + deploy: needs: build runs-on: [self-hosted, Linux, X64] steps: - - run: chmod +x ./deploy.sh - - run: echo ${{ secrets.DVNS_CLUSTER_PASSWORD }} | sudo -S ./deploy.sh + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Make deploy.sh executable + run: chmod +x ./deploy.sh + - name: Execute deploy.sh + run: echo "${{ secrets.DVNS_CLUSTER_PASSWORD }}" | sudo -S ./deploy.sh "$(pwd)/dist/" "${{ secrets.CERT_PATH }}" diff --git a/deploy.sh b/deploy.sh index 6094e64..facbc2d 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,14 +1,12 @@ #!/bin/bash -source /etc/marquinhos/marquinhos-api.conf +MARQUINHOS_PATH="/etc/marquinhos/" +source "${MARQUINHOS_PATH}marquinhos-api.conf" -CERTIFICATE_PATH="/home/guilherme/certificates/marquinhos/server.crt" -KEY_PATH="/home/guilherme/certificates/marquinhos/server.key" +DESTINATION_DIR="$1" -DESTINATION_DIR="/home/guilherme/github-runners/devaneios-runner/_work/marquinhos-web-api/marquinhos-web-api/dist" - -cp "$CERTIFICATE_PATH" "$DESTINATION_DIR" -cp "$KEY_PATH" "$DESTINATION_DIR" +cp "${MARQUINHOS_PATH}server.crt" "$DESTINATION_DIR" +cp "${MARQUINHOS_PATH}server.key" "$DESTINATION_DIR" chmod 744 "$DESTINATION_DIR/server.key" chmod 744 "$DESTINATION_DIR/server.crt" @@ -33,14 +31,15 @@ Environment="DISCORD_REDIRECT_URI=$DISCORD_REDIRECT_URI" Environment="LASTFM_REDIRECT_URI=$LASTFM_REDIRECT_URI" Environment="SPOTIFY_CLIENT_ID=$SPOTIFY_CLIENT_ID" Environment="SPOTIFY_CLIENT_SECRET=$SPOTIFY_CLIENT_SECRET" +Environment="NODE_ENV=production" User=guilherme KillMode=control-group -WorkingDirectory=/home/guilherme/github-runners/devaneios-runner/_work/marquinhos-web-api/marquinhos-web-api/dist +WorkingDirectory=$DESTINATION_DIR -ExecStart=/home/guilherme/.nvm/versions/node/v18.13.0/bin/node ./index.js +ExecStart=node ./index.js Restart=always