Skip to content

Update dev-deploy.yml #2

Update dev-deploy.yml

Update dev-deploy.yml #2

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go
on:
pull_request:
types:
- closed
jobs:
build:
if: github.event.pull_request.merged
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker image
run: |
docker buildx build --platform linux/amd64 -t sast/sast-link -f docker/Dockerfile --output type=docker,dest=image.tar .
- name: Deploy to Server
id: deploy
uses: easingthemes/ssh-deploy@main
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i --delete"
SOURCE: "./image.tar"
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
TARGET: /tmp/image.tar
SCRIPT_AFTER: |
### Notice: run for develop ###
# Stop and remove existing container if it exists
if [ "$(docker ps -aq -f name=sastlink)" ]; then
docker stop sastlink
docker rm sastlink
fi
# Remove existing image if it exists
if [ "$(docker images -q sast/sast-link)" ]; then
docker rmi sast/sast-link
fi
# Load the new image and run it
docker load -i ~/image.tar
docker run -d --name sastlink -p 8080:8080 sast/sast-link
echo "---------"
echo $RSYNC_STDOUT
echo "---------"
RSYNC_STDOUT: ${{ env.RSYNC_STDOUT }}
- name: Check Deployment Status
run: |
if [[ "${{ steps.deploy.outputs.RSYNC_STDOUT }}" == *"error"* ]]; then
echo "Deployment failed"
exit 1
fi
- name: Send Success Message
if: ${{ success() }}
run: |
bash ./scripts/webhook.sh \
-u "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-w ${{ secrets.WEBHOOK_URL }} \
-s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'success' \
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}"
- name: Send Fail Message
if: ${{ failure() }}
run: |
bash ./scripts/webhook.sh \
-u "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-w ${{ secrets.WEBHOOK_URL }} \
-s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'failure' \
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}"