Skip to content

Add bonus content provided by @chgeuer #68

Add bonus content provided by @chgeuer

Add bonus content provided by @chgeuer #68

Workflow file for this run

name: CI
on:
push:
branches: [ main ]
pull_request:
env:
REGISTRY: ghcr.io
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: read
container:
image: ghcr.io/lostkobrakai/uberspace:centos-7
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
MIX_ENV: prod
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Cache
uses: actions/cache@v3
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-
- run: mix local.hex --force
- run: mix local.rebar --force
- name: Fetch dependencies
run: mix deps.get --only $MIX_ENV
- name: Build assets
run: mix assets.deploy
- name: Build release
run: mix release --path release
- name: Archive release
uses: actions/upload-artifact@v3
with:
name: release
path: |
release/*.tar.gz
deployment:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
environment: production
concurrency: production
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/prod.key
chmod 600 ~/.ssh/prod.key
cat >>~/.ssh/config <<END
Host prod
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/prod.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.USER }}
SSH_KEY: ${{ secrets.DEPLOY_KEY }}
SSH_HOST: ${{ secrets.HOST }}
- name: Fetch release
uses: actions/download-artifact@v3
with:
name: release
- name: Push release to server
run: rsync -avz -e ssh . prod:/home/${{ secrets.USER }}/kobrakai
- name: Restart service with new release
run: ssh prod 'bash /home/${{ secrets.USER }}/kobrakai/restart.sh'