Skip to content

Merge pull request #278 from AndrewCS149/revertPR #43

Merge pull request #278 from AndrewCS149/revertPR

Merge pull request #278 from AndrewCS149/revertPR #43

Workflow file for this run

name: Deploy
on:
workflow_dispatch:
inputs:
input:
required: false
push:
branches:
- staging
- master
jobs:
build-client:
name: Build Client
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- name: Cache Trunk
uses: actions/cache@v3
with:
path: |
~/.cargo
/usr/local/cargo/bin
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
toolchain: stable
- name: Install Trunk
run: cargo install trunk
if: steps.cache.outputs.cache-hit != 'true'
- name: Build with Trunk
run: |
echo ${{ secrets.API_URL }} > src/api_url.txt
trunk build --release
working-directory: client
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: clientArtifact
path: client/dist
- name: Upload Dockerfile
uses: actions/upload-artifact@v4
with:
name: clientDockerfile
path: client/Dockerfile
build-server:
name: Build Server
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore ./server/devblog.csproj
- name: Build application
run: dotnet build ./server/devblog.csproj -c Release -o ./app/build
- name: Publish application
run: dotnet publish ./server/devblog.csproj -c Release -o ./app/publish /p:UseAppHost=false
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: serverArtifact
path: app/publish
- name: Upload Dockerfile
uses: actions/upload-artifact@v4
with:
name: serverDockerfile
path: server/Dockerfile
- name: Upload Docker Compose
uses: actions/upload-artifact@v4
with:
name: dockerCompose
path: docker-compose.yml
copy-files:
name: Copy Files
needs: [build-server, build-client]
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- name: Create SSH Key
run: |
mkdir -p ${{ secrets.SSH_PRIVATE_KEY_PATH }}
echo "${{ secrets.SSH_PRIVATE_KEY_CONTENT }}" > ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }}
sudo chmod 600 ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }}
shell: bash
- name: Add Host Key to known_hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ${{ secrets.SSH_PRIVATE_KEY_PATH }}/known_hosts
- name: Download Client Artifacts
uses: actions/download-artifact@v4
with:
name: clientArtifact
path: dist
- name: Download Server Artifacts
uses: actions/download-artifact@v4
with:
name: serverArtifact
path: publish
- name: Download Server Dockerfile
uses: actions/download-artifact@v4
with:
name: serverDockerfile
path: server
- name: Download Client Dockerfile
uses: actions/download-artifact@v4
with:
name: clientDockerfile
path: client
- name: Download Docker Compose
uses: actions/download-artifact@v4
with:
name: dockerCompose
path: dockerCompose
- name: Copy Files to Server
run: |
scp -i ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }} dockerCompose/docker-compose.yml ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.DEVBLOG_ROOT_PATH }}
scp -i ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }} -r client/Dockerfile dist ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.DEVBLOG_ROOT_PATH }}/client
scp -i ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }} -r server/Dockerfile publish ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.DEVBLOG_ROOT_PATH }}/server
restart-containers:
name: Restart Containers
needs: [copy-files]
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- name: Create SSH Key
run: |
mkdir -p ${{ secrets.SSH_PRIVATE_KEY_PATH }}
echo "${{ secrets.SSH_PRIVATE_KEY_CONTENT }}" > ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }}
sudo chmod 600 ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }}
shell: bash
- name: Add Host Key to known_hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ${{ secrets.SSH_PRIVATE_KEY_PATH }}/known_hosts
- name: Restart Container
run: |
ssh -i ${{ secrets.SSH_PRIVATE_KEY_PATH }}/${{ secrets.SSH_PRIVATE_KEY_NAME }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "\
cd ${{ secrets.DEVBLOG_ROOT_PATH }} && \
docker compose up -d --force-recreate"