Skip to content

test

test #4

Workflow file for this run

name: cicd
on:
push:
branches:
- main
pull_request:
types:
- closed
branches:
- main
jobs:
build-and-push:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
permissions:
packages: write
outputs:
owner: ${{ steps.lower.outputs.owner }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Repository owner lowercase
id: lower
run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Build and Push Docker
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ghcr.io/${{ steps.lower.outputs.owner }}/weesh-client:latest
build-args: |
SPRING_BOOT_API_URL=${{ secrets.SPRING_BOOT_API_URL }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Add SSH key
uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: ${{ secrets.EC2_SSH_KEY }}
- name: Deploy to EC2
run: |
ssh -o StrictHostKeyChecking=no ec2-user@${{ secrets.EC2_HOST }} << 'EOF'
docker pull ghcr.io/${{ needs.build-and-push.outputs.owner }}/weesh-client:latest
docker stop weesh-client || true
docker rm weesh-client || true
docker run --network weesh-net -d --name weesh-client -p 80:3000 ghcr.io/${{ needs.build-and-push.outputs.owner }}/weesh-client:latest
EOF