Skip to content

Commit

Permalink
fix: warmup service with fixed deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
d0lim committed Sep 14, 2023
1 parent 9d470a4 commit 369f6bd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ jobs:
push: true
platforms: linux/amd64
tags: ${{ secrets.REGISTRY_HOST }}/studium-server:latest
# docker-pull-and-restart:
# environment: dev
# runs-on: ubuntu-latest
# needs: docker-build-and-push
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: create ansible secrets
# run: |
# touch ./ansible/secrets.yml
# echo "user: '${{ secrets.ANSIBLE_USER }}'" >> ./ansible/secrets.yml
# echo "registry_host: '${{ secrets.REGISTRY_HOST }}'" >> ./ansible/secrets.yml
# echo "registry_user: '${{ secrets.REGISTRY_ID }}'" >> ./ansible/secrets.yml
# echo "registry_password: '${{ secrets.REGISTRY_PASSWORD }}'" >> ./ansible/secrets.yml
# - name: Run Playbook
# uses: dawidd6/action-ansible-playbook@v2
# with:
# playbook: deploy-playbook.yml
# directory: ./ansible
# key: ${{secrets.SSH_PRIVATE_KEY}}
# inventory: ${{secrets.ANSIBLE_INVENTORY}}
docker-pull-and-restart:
environment: dev
runs-on: ubuntu-latest
needs: docker-build-and-push
steps:
- name: Checkout
uses: actions/checkout@v3
- name: create ansible secrets
run: |
touch ./ansible/secrets.yml
echo "user: '${{ secrets.ANSIBLE_USER }}'" >> ./ansible/secrets.yml
echo "registry_host: '${{ secrets.REGISTRY_HOST }}'" >> ./ansible/secrets.yml
echo "registry_user: '${{ secrets.REGISTRY_ID }}'" >> ./ansible/secrets.yml
echo "registry_password: '${{ secrets.REGISTRY_PASSWORD }}'" >> ./ansible/secrets.yml
- name: Run Playbook
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: deploy-playbook.yml
directory: ./ansible
key: ${{secrets.SSH_PRIVATE_KEY}}
inventory: ${{secrets.ANSIBLE_INVENTORY}}
18 changes: 18 additions & 0 deletions ansible/deploy-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@
args:
chdir: /Users/{{ user }}/Server
executable: /bin/zsh
- name: Log into private registry and force re-authorization
become: True
shell: "/usr/bin/docker login {{ registry_host }} -u {{ registry_user }} -p {{ registry_password }}"
args:
chdir: "/home/{{ user }}/compose"
executable: /usr/bin/zsh
- name: Pull image
become: True
shell: "/usr/bin/docker pull {{ registry_host }}/studium-server:latest"
args:
chdir: "/home/{{ user }}/compose"
executable: "/usr/bin/zsh"
- name: Restart Container
become: True
shell: "/usr/bin/zsh node-env.sh && source ~/.zshrc && /usr/bin/docker service update --force --image {{ registry_host }}/studium-server:latest studium_studium-server"
args:
chdir: "/home/{{ user }}/compose"
executable: "/usr/bin/zsh"
24 changes: 14 additions & 10 deletions src/common/warmup/warmup.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HttpService } from '@nestjs/axios';
import { Injectable, OnApplicationBootstrap, Logger } from '@nestjs/common';
import { tap, map } from 'rxjs';
import { tap, map, catchError, of } from 'rxjs';

@Injectable()
export class WarmupService implements OnApplicationBootstrap {
readonly turnstileSyncEndpoint = 'https://api.server.d0lim.com/turnstile/internal/api/v1/service-endpoint';
readonly turnstileSyncEndpoint = 'https://turnstile.server.d0lim.com/internal/api/v1/service-endpoint';

constructor(private readonly httpService: HttpService) {}

Expand All @@ -20,13 +20,17 @@ export class WarmupService implements OnApplicationBootstrap {
public_endpoints: publicEndpoints,
};

// disable temporarily for turnstile deploy issue
// this.httpService
// .post(this.turnstileSyncEndpoint, requestBody)
// .pipe(
// tap((res) => console.log(res)),
// map((res) => res.data),
// )
// .subscribe();
this.httpService
.post(this.turnstileSyncEndpoint, requestBody)
.pipe(
catchError((err) =>
of({
data: `error occurred, ${err}`,
}),
),
tap((res) => console.log(res)),
map((res) => res.data),
)
.subscribe();
}
}

0 comments on commit 369f6bd

Please sign in to comment.