Skip to content

Added persistence

Added persistence #58

Workflow file for this run

name: Build and deploy
on:
pull_request:
branches:
- master
push:
branches:
- master
workflow_dispatch:
env:
out_dir: ${{ vars.OUTPUT_DIR }}
tag: ${{ github.ref == format('refs/heads/{0}', 'master') && 'latest' || format('pr-{0}', github.event.pull_request.number) }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Restore tools
run: dotnet tool restore
- name: Push
run: echo "${{ github.token }}" | dotnet cake --target Push --tag ${tag}
deploy-test:
needs:
- build
runs-on: [host, ARM64]
environment: test
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Update DockerCompose
run: |
mkdir -p $out_dir
cp src/docker-compose.yml $out_dir
cd $out_dir
cat << EOF > docker-compose.override.yml
services:
server:
image: ghcr.io/${{ github.repository }}:${tag}-arm64v8
db-init:
image: ghcr.io/${{ github.repository }}:${tag}-arm64v8
EOF
cat << EOF > server.env
DOTNET_ENVIRONMENT: Development
PILLSBOT__TELEGRAM__APITOKEN: ${{ secrets.PILLSBOT__TELEGRAM__APITOKEN }}
PILLSBOT__TELEGRAM__CHATID: "${{ secrets.PILLSBOT__TELEGRAM__CHATID }}"
PILLSBOT__REMINDER__INTERVAL: ${{ vars.PILLSBOT__REMINDER__INTERVAL }}
PILLSBOT__AI__ENABLED: ${{ vars.PILLSBOT__AI__ENABLED }}
PILLSBOT__AI__LANGUAGES: ${{ secrets.PILLSBOT__AI__LANGUAGES }}
PILLSBOT__AI__PETNAMES: ${{ secrets.PILLSBOT__AI__PETNAMES }}
PILLSBOT__AI__PETGENDER: ${{ secrets.PILLSBOT__AI__PETGENDER }}
PILLSBOT__AI__LOGLEVEL: ${{ vars.PILLSBOT__AI__LOGLEVEL }}
PILLSBOT__AI__MAXTOKENS: ${{ vars.PILLSBOT__AI__MAXTOKENS }}
PILLSBOT__AI__CHOICESCOUNT: ${{ vars.PILLSBOT__AI__CHOICESCOUNT }}
PILLSBOT__AI__AZURE__ENDPOINT: ${{ secrets.PILLSBOT__AI__AZURE__ENDPOINT }}
PILLSBOT__AI__AZURE__KEY: ${{ secrets.PILLSBOT__AI__AZURE__KEY }}
PILLSBOT__AI__AZURE__DEPLOYMENTNAME: ${{ secrets.PILLSBOT__AI__AZURE__DEPLOYMENTNAME }}
APPLICATIONINSIGHTS__CONNECTIONSTRING: ${{ secrets.APPLICATIONINSIGHTS__CONNECTIONSTRING }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
CONNECTIONSTRINGS__PILLSBOTDBCONTEXT: Host=db;Database=${{ secrets.POSTGRES_DB }};Username=${{ secrets.POSTGRES_USER }};Password=${{ secrets.POSTGRES_PASSWORD }}
EOF
- name: Restart
run: |
cd $out_dir
docker compose up --detach --pull always --quiet-pull --remove-orphans --wait --wait-timeout 60
deploy-prod:
if: ${{ github.ref == format('refs/heads/{0}', 'master') }}
needs:
- build
- deploy-test
runs-on: [host, ARM64]
environment: prod
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Update DockerCompose
run: |
mkdir -p $out_dir
cp src/docker-compose.yml $out_dir
cd $out_dir
cat << EOF > docker-compose.override.yml
services:
server:
image: ghcr.io/${{ github.repository }}:${tag}-arm64v8
db-init:
image: ghcr.io/${{ github.repository }}:${tag}-arm64v8
EOF
cat << EOF > server.env
DOTNET_ENVIRONMENT: Production
PILLSBOT__TELEGRAM__APITOKEN: ${{ secrets.PILLSBOT__TELEGRAM__APITOKEN }}
PILLSBOT__TELEGRAM__CHATID: "${{ secrets.PILLSBOT__TELEGRAM__CHATID }}"
PILLSBOT__REMINDER__BEGINS: ${{ secrets.PILLSBOT__REMINDER__BEGINS }}
PILLSBOT__AI__ENABLED: ${{ vars.PILLSBOT__AI__ENABLED }}
PILLSBOT__AI__LANGUAGES: ${{ secrets.PILLSBOT__AI__LANGUAGES }}
PILLSBOT__AI__PETNAMES: ${{ secrets.PILLSBOT__AI__PETNAMES }}
PILLSBOT__AI__PETGENDER: ${{ secrets.PILLSBOT__AI__PETGENDER }}
PILLSBOT__AI__LOGLEVEL: ${{ vars.PILLSBOT__AI__LOGLEVEL }}
PILLSBOT__AI__MAXTOKENS: ${{ vars.PILLSBOT__AI__MAXTOKENS }}
PILLSBOT__AI__CHOICESCOUNT: ${{ vars.PILLSBOT__AI__CHOICESCOUNT }}
PILLSBOT__AI__AZURE__ENDPOINT: ${{ secrets.PILLSBOT__AI__AZURE__ENDPOINT }}
PILLSBOT__AI__AZURE__KEY: ${{ secrets.PILLSBOT__AI__AZURE__KEY }}
PILLSBOT__AI__AZURE__DEPLOYMENTNAME: ${{ secrets.PILLSBOT__AI__AZURE__DEPLOYMENTNAME }}
APPLICATIONINSIGHTS__CONNECTIONSTRING: ${{ secrets.APPLICATIONINSIGHTS__CONNECTIONSTRING }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
CONNECTIONSTRINGS__PILLSBOTDBCONTEXT: Host=db;Database=${{ secrets.POSTGRES_DB }};Username=${{ secrets.POSTGRES_USER }};Password=${{ secrets.POSTGRES_PASSWORD }}
EOF
- name: Restart
run: |
cd $out_dir
docker compose up --detach --pull always --quiet-pull --remove-orphans --wait --wait-timeout 60