generated from NetCoreTemplates/razor-ssg
-
Notifications
You must be signed in to change notification settings - Fork 3
135 lines (124 loc) · 5.45 KB
/
search-index-update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Build Search Index
permissions:
packages: write
contents: write
on:
schedule:
# Run once a day
- cron: '10 0 * * *'
workflow_dispatch:
inputs:
noop:
description: 'noop'
required: false
default: 'noop'
jobs:
build:
runs-on: ubuntu-latest
outputs:
run_update: ${{ steps.date_check.outputs.run_update }}
steps:
- uses: actions/checkout@v1
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 14
- name: Check commit date
id: date_check
run: |
chmod +x ./search-server/commit-date-check.sh
echo "$(./search-server/commit-date-check.sh)"
echo "run_update=$(./search-server/commit-date-check.sh)" >> $GITHUB_ENV
- name: GH script check
uses: actions/github-script@v7
id: check
with:
script: |
const { owner, repo } = context.repo
const update = ${{ env.run_update == 'update' }}
if (!update) {
console.log('Cancelling ...');
const run_id = "${{ github.run_id }}";
await github.rest.actions.cancelWorkflowRun({ owner, repo, run_id });
return 'stop'
} else {
return 'build'
}
result-encoding: string
- name: Waiting for cancellation
run: sleep 60
if: steps.check.outputs.result == 'stop'
- name: Create search index
run: |
echo "TYPESENSE_API_KEY=${{ secrets.TYPESENSE_API_KEY }}" >> $GITHUB_ENV
export TYPESENSE_API_KEY=${{ secrets.TYPESENSE_API_KEY }}
mkdir -p ${GITHUB_WORKSPACE}/typesense-data
cp ./search-server/typesense-server/Dockerfile ${GITHUB_WORKSPACE}/typesense-data/Dockerfile
cp ./search-server/typesense-scraper/typesense-scraper-config.json typesense-scraper-config.json
envsubst < "./search-server/typesense-scraper/typesense-scraper.env" > "typesense-scraper-updated.env"
docker run -d -p 8108:8108 -v ${GITHUB_WORKSPACE}/typesense-data/data:/data typesense/typesense:0.21.0 --data-dir /data --api-key=${TYPESENSE_API_KEY} --enable-cors &
sleep 5
docker run -i --env-file typesense-scraper-updated.env -e "CONFIG=$(cat typesense-scraper-config.json | jq -r tostring)" typesense/docsearch-scraper
curl 'http://172.17.0.2:8108/keys' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -H 'Content-Type: application/json' -d '{"value": "N4N8bF0XwyvzwCGwm3CKB0QcnwyWtygo","description": "Search only","actions": ["documents:search"],"collections":["*"]}'
- name: repository name fix and env
run: |
echo "letsencrypt_email=${{ secrets.LETSENCRYPT_EMAIL }}" >> $GITHUB_ENV
echo "TAG_NAME=latest" >> $GITHUB_ENV
if [ "${{ github.event.release.tag_name }}" != "" ]; then
echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
fi;
if [ "${{ github.event.inputs.version }}" != "" ]; then
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
fi;
echo "image_repository_name=servicestack/docs-search" >> $GITHUB_ENV
echo "domain=search.docs.servicestack.net" >> $GITHUB_ENV
echo "letsencrypt_email=${{ secrets.LETSENCRYPT_EMAIL }}" >> $GITHUB_ENV
echo "app_name=servicestack-docs-search" >> $GITHUB_ENV
echo "typesense_api_key=${{ secrets.TYPESENSE_API_KEY }}" >> $GITHUB_ENV
- name: Write .env file
run: |
echo "HOST_DOMAIN=${{ env.domain }}" > .env
echo "LETSENCRYPT_EMAIL=${{ env.letsencrypt_email }}" >> .env
echo "TYPESENSE_API_KEY=${{ env.typesense_api_key }}" >> .env
cp search-server/typesense-server/docker-compose.yml ./
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@v3
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
with:
file: ./typesense-data/Dockerfile
context: ./typesense-data/
push: true
tags: ghcr.io/${{ env.image_repository_name }}:${{ env.TAG_NAME }}
# Copy only the docker-compose.yml to remote server home folder
- name: copy compose file via scp
uses: appleboy/[email protected]
with:
host: 52.201.116.245
username: ${{ secrets.DEPLOY_USERNAME }}
port: 22
key: ${{ secrets.DEPLOY_KEY }}
source: "docker-compose.yml,.env"
target: "~/.deploy/docs-typesense"
# Deploy Docker image with ServiceStack application using `docker compose up` remotely
- name: remote docker-compose up via ssh
uses: appleboy/[email protected]
env:
APPTOKEN: ${{ secrets.GITHUB_TOKEN }}
USERNAME: ${{ secrets.DEPLOY_USERNAME }}
with:
host: 52.201.116.245
username: ${{ secrets.DEPLOY_USERNAME }}
key: ${{ secrets.DEPLOY_KEY }}
port: 22
envs: APPTOKEN,USERNAME
script: |
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
cd ~/.deploy/docs-typesense
docker-compose pull
docker-compose up -d