Skip to content

Update push.yml

Update push.yml #22

Workflow file for this run

name: Build and Deploy on Push or Release
on:
push:
branches:
- master
release:
types:
- published
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Docker Image
run: |
COMMIT_HASH=$(echo $GITHUB_SHA | cut -c1-7)
docker buildx create --use
if [[ "${{ github.event_name }}" == "release" ]]; then
TAG_PREFIX="prod"
elif [[ "${GITHUB_REF_NAME}}" == "release" ]]; then
TAG_PREFIX="prod"
else
TAG_PREFIX="stage"
fi
docker buildx build --platform linux/amd64,linux/arm64 \
-t devinfritz/vzbot-discordbot:${TAG_PREFIX}-${COMMIT_HASH} \
-t devinfritz/vzbot-discordbot:${TAG_PREFIX}-latest \
--push .
deploy:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Execute remote SSH commands
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: github
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_SSH_PORT }}
script: |
if [[ "${{ github.event_name }}" == "release" ]]; then
./deploy.sh production
elif [[ "${GITHUB_REF_NAME}}" == "release" ]]; then
./deploy.sh production
else
./deploy.sh stage
fi