🐛 kku firewall #175
This file contains 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: Build & Deploy | |
on: | |
push: | |
branches: | |
- main | |
env: | |
IMAGE_NAME: ghcr.io/${{ github.repository }} | |
jobs: | |
build-and-deploy: | |
strategy: | |
matrix: | |
node-version: [16.x] | |
platform: [ubuntu-latest] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to the Container registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up environment | |
run: | | |
echo "NEXT_PUBLIC_SEGMENT_API_KEY=${{ secrets.SEGMENT_API_KEY }}" >> .env.local | |
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env.local | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.IMAGE_NAME }}:latest | |
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache | |
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max | |
- name: Install Open VPN | |
run: sudo apt update && sudo apt install openvpn | |
- name: Connect VPN | |
uses: golfzaptw/[email protected] | |
id: connect_vpn | |
with: | |
PING_URL: ${{ secrets.SSH_HOST }} | |
FILE_OVPN: '.github/vpn/config.ovpn' | |
SECRET: ${{ secrets.VPN_SECRET_USERNAME_PASSWORD }} | |
env: | |
CA_CRT: ${{ secrets.VPN_CA_CRT}} | |
USER_CRT: ${{ secrets.VPN_USER_CRT }} | |
USER_KEY: ${{ secrets.VPN_USER_KEY }} | |
- name: Check Connect VPN | |
run: echo ${{ steps.connect_vpn.outputs.STATUS }} | |
- name: Deploy to host | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
script_stop: true | |
script: | | |
docker pull ${{ env.IMAGE_NAME }}:latest | |
cd otog-frontend | |
git checkout main; git pull | |
docker compose -f docker-compose.prod.yml up -d | |
docker image prune -f | |
- name: kill vpn | |
if: always() | |
run: sudo killall openvpn |