try workflow #6
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 and deploy web app | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'cmd/app/**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-buildx-action@v3 | |
- uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile.app | |
push: true | |
tags: ghcr.io/thedmdim/ytstalker/app:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
deploy: | |
needs: build | |
name: deploy image | |
runs-on: ubuntu-latest | |
steps: | |
- name: prepare ssh | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H "$SERVER_IP" >> ~/.ssh/known_hosts | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SERVER_IP: ${{ secrets.SERVER_IP }} | |
- name: SSH into the server and update the code | |
run: | | |
ssh $SERVER_USERNAME@$SERVER_IP \ | |
"wget -qO - https://raw.githubusercontent.com/thedmdim/ytstalker/master/docker-compose.yml > /root/ytstalker/docker-compose.yml \ | |
&& wget -qO - https://raw.githubusercontent.com/thedmdim/ytstalker/master/Caddyfile > /root/ytstalker/Caddyfile \ | |
&& docker compose -f /root/ytstalker/docker-compose.yml up --pull always -d app caddy" | |
env: | |
SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }} | |
SERVER_IP: ${{ secrets.SERVER_IP }} |