Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 14 additions & 113 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ on:
branches: ['**']
push:
branches: ['master']
workflow_dispatch:
inputs:
environment:
description: Target environment for deployment
required: true
type: choice
options:
- sirch
tags: [v*]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

compile:
if: github.event_name != 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -29,7 +26,6 @@ jobs:
- run: sbt compile

lint:
if: github.event_name != 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -42,7 +38,6 @@ jobs:
- run: sbt check

test:
if: github.event_name != 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -54,107 +49,13 @@ jobs:
uses: sbt/setup-sbt@v1
- run: sbt test

stage:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Setup sbt
uses: sbt/setup-sbt@v1
- run: sbt stage
- uses: actions/upload-artifact@v4
with:
name: lila-search-app
path: modules/app/target/universal/stage
- uses: actions/upload-artifact@v4
with:
name: lila-search-ingestor
path: modules/ingestor-app/target/universal/stage
- uses: actions/upload-artifact@v4
with:
name: lila-search-cli
path: modules/ingestor-cli/target/universal/stage

# todo
# - auto matically run on tag or workflow_dispatch
# - tpolecat release mode

deploy-components:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
needs: stage
environment:
name: ${{ inputs.environment }}
strategy:
fail-fast: false
matrix:
include:
- artifact: lila-search-app
remote_dir: /home/lila-search
user: lila-search-app
restart_cmd: systemctl restart lila-search
- artifact: lila-search-ingestor
remote_dir: /home/lila-search-ingestor
user: lila-search-ingestor
restart_cmd: systemctl restart lila-search-ingestor
- artifact: lila-search-cli
remote_dir: /home/lila-search-cli
user: lila-search-cli
restart_cmd: "" # no restart needed
concurrency:
group: deploy-${{ inputs.environment }}-${{ matrix.artifact }}
steps:
- name: Download artifact (will fail if artifact not present from a prior run)
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact }}
path: stage

- name: Configure SSH
run: |
set -euo pipefail
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/id_deploy
chmod 600 ~/.ssh/id_deploy
echo "$SSH_KEY" > ~/.ssh/id_deploy
echo "$SSH_HOST $SSH_HOST_KEY" > ~/.ssh/known_hosts
cat >>~/.ssh/config <<END
Host deploy-host
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/id_deploy
StrictHostKeyChecking yes
END
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST_KEY: ${{ secrets.SSH_HOST_KEY }}

- name: Deploy via SSH
run: |
set -euo pipefail
if [ ! -d stage/bin ]; then
echo "ERROR: Expected staged artifact (stage/bin) not found. You skipped build jobs via workflow_dispatch."
echo "Either (a) run a normal CI build first, or (b) modify deploy job to build artifacts."
exit 1
fi
RSYNC_OPTIONS="--archive --no-o --no-g --force --delete --progress --compress --checksum --verbose --exclude RUNNING_PID --exclude '.git/'"
include="stage/bin stage/lib"
echo "Deploying ${{ matrix.artifact }} to ${{ matrix.remote_dir }}"
rsync $RSYNC_OPTIONS $include deploy-host:${{ matrix.remote_dir }}
echo "rsync complete (${{ matrix.artifact }})"
deploy:
uses: ./.github/workflows/deploy.yml
with:
env: sirch
secrets: inherit

if [ -n "${{ matrix.restart_cmd }}" ]; then
echo "run restart: ${{ matrix.restart_cmd }}"
ssh deploy-host "chown -R ${{ matrix.user }}:${{ matrix.user }} ${{ matrix.remote_dir }} && ${{ matrix.restart_cmd }}"
else
echo "No restart command defined for ${{ matrix.artifact }}."
fi
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/v'))

echo "Deploy complete (${{ matrix.artifact }})"
needs:
- test
120 changes: 120 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: CI

on:
workflow_dispatch:
inputs:
env:
required: true
type: choice
options:
- sirch
workflow_call:
env:
description: Target environment for deployment
required: true
type: string

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

stage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Setup sbt
uses: sbt/setup-sbt@v1
- run: sbt stage
- uses: actions/upload-artifact@v4
with:
name: lila-search-app
path: modules/app/target/universal/stage
- uses: actions/upload-artifact@v4
with:
name: lila-search-ingestor
path: modules/ingestor-app/target/universal/stage
- uses: actions/upload-artifact@v4
with:
name: lila-search-cli
path: modules/ingestor-cli/target/universal/stage

deploy-components:
runs-on: ubuntu-latest
needs: stage
environment:
name: ${{ inputs.environment }}
strategy:
fail-fast: false
matrix:
include:
- artifact: lila-search-app
remote_dir: /home/lila-search
user: lila-search-app
restart_cmd: systemctl restart lila-search
- artifact: lila-search-ingestor
remote_dir: /home/lila-search-ingestor
user: lila-search-ingestor
restart_cmd: systemctl restart lila-search-ingestor
- artifact: lila-search-cli
remote_dir: /home/lila-search-cli
user: lila-search-cli
restart_cmd: "" # no restart needed
concurrency:
group: deploy-${{ inputs.environment }}-${{ matrix.artifact }}
steps:
- name: Download artifact (will fail if artifact not present from a prior run)
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact }}
path: stage

- name: Configure SSH
run: |
set -euo pipefail
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/id_deploy
chmod 600 ~/.ssh/id_deploy
echo "$SSH_KEY" > ~/.ssh/id_deploy
echo "$SSH_HOST $SSH_HOST_KEY" > ~/.ssh/known_hosts
cat >>~/.ssh/config <<END
Host deploy-host
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/id_deploy
StrictHostKeyChecking yes
END
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST_KEY: ${{ secrets.SSH_HOST_KEY }}

- name: Deploy via SSH
run: |
set -euo pipefail
if [ ! -d stage/bin ]; then
echo "ERROR: Expected staged artifact (stage/bin) not found. You skipped build jobs via workflow_dispatch."
echo "Either (a) run a normal CI build first, or (b) modify deploy job to build artifacts."
exit 1
fi
RSYNC_OPTIONS="--archive --no-o --no-g --force --delete --progress --compress --checksum --verbose --exclude RUNNING_PID --exclude '.git/'"
include="stage/bin stage/lib"
echo "Deploying ${{ matrix.artifact }} to ${{ matrix.remote_dir }}"
rsync $RSYNC_OPTIONS $include deploy-host:${{ matrix.remote_dir }}
echo "rsync complete (${{ matrix.artifact }})"

if [ -n "${{ matrix.restart_cmd }}" ]; then
echo "run restart: ${{ matrix.restart_cmd }}"
ssh deploy-host "chown -R ${{ matrix.user }}:${{ matrix.user }} ${{ matrix.remote_dir }} && ${{ matrix.restart_cmd }}"
else
echo "No restart command defined for ${{ matrix.artifact }}."
fi

echo "Deploy complete (${{ matrix.artifact }})"