deploy via ci #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: Target environment for deployment | |
| required: true | |
| type: choice | |
| options: | |
| - eight | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/build-push-action@v6 | |
| with: | |
| cache-from: type | |
| cache-to: type=gha | |
| outputs: type=local,dest=dist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: op1-server | |
| path: dist/usr/local/bin/op1-server | |
| deploy: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: ${{ inputs.environment }} | |
| concurrency: | |
| group: ${{ inputs.environment }} | |
| needs: build | |
| if: github.event_name == 'workflow_dispatch' | |
| steps: | |
| - uses: actions/download-artifact@v5 | |
| with: | |
| name: op1-server | |
| - name: Configure SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| touch ~/.ssh/id_deploy | |
| chmod 600 ~/.ssh/id_deploy | |
| echo "$SSH_KEY" ~/.ssh/id_deploy | |
| echo "$SSH_HOST $SSH_HOST_KEY" > ~/.ssh/known_hosts | |
| cat >>~/.ssh/config <<END | |
| Host deploy-host | |
| HostName $SSH_HOST | |
| User $SSH_USER | |
| IdentityFile ~/.ssh/id_deploy | |
| StrictHostKeyChecking yes | |
| END | |
| env: | |
| SSH_KEY: ${{ secrets.SSH_KEY }} | |
| SSH_HOST: ${{ secrets.SSH_HOST }} | |
| SSH_HOST_KEY: ${{ secrets.SSH_HOST_KEY }} | |
| SSH_USER: ${{ secrets.SSH_USER }} | |
| - name: Deploy via SSH | |
| run: cat op1-server | ssh deploy-host "mv /usr/local/bin/op1-server /usr/local/bin/op1-server.bak && cat - > /usr/local/bin/op1-server && chmod +x /usr/local/bin/op1-server && systemctl restart op1-server" |