chore: Deploy to k8s #121
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Release to Staging" | |
on: | |
push: | |
branches: | |
- main | |
- k8s-deployment | |
paths: | |
- "backend/**" | |
- "chatbot/**" | |
- "webapp/**" | |
- ".github/workflows/release.yml" | |
concurrency: | |
group: release-staging | |
jobs: | |
check-changed-apps: | |
runs-on: ubuntu-latest | |
outputs: | |
changed-files-backend: ${{ steps.changed-files-backend.outputs.any_changed }} | |
changed-files-chatbot: ${{ steps.changed-files-chatbot.outputs.any_changed }} | |
changed-files-webapp: ${{ steps.changed-files-webapp.outputs.any_changed }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Check changes on backend | |
id: changed-files-backend | |
uses: tj-actions/changed-files@v39 | |
with: | |
since_last_remote_commit: true | |
files: | | |
backend/** | |
.github/** | |
- name: Check changes on chatbot | |
id: changed-files-chatbot | |
uses: tj-actions/changed-files@v39 | |
with: | |
since_last_remote_commit: true | |
files: | | |
chatbot/** | |
.github/** | |
- name: Check changes on webapp | |
id: changed-files-webapp | |
uses: tj-actions/changed-files@v39 | |
with: | |
since_last_remote_commit: true | |
files: | | |
webapp/** | |
.github/** | |
release-backend-staging: | |
needs: check-changed-apps | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
concurrency: | |
group: wireguard | |
if: needs.check-changed-apps.outputs.changed-files-backend == 'true' | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup wireguard | |
uses: egor-tensin/setup-wireguard@v1 | |
with: | |
endpoint: ${{ secrets.WG_ENDPOINT }} | |
endpoint_public_key: ${{ secrets.WG_ENDPOINT_PUBLIC_KEY }} | |
private_key: ${{ secrets.WG_PRIVATE_KEY }} | |
ips: ${{ secrets.WG_IPS }} | |
allowed_ips: ${{ secrets.WG_ALLOWED_IPS }} | |
- name: Check VPN connection | |
run: ping -c1 ${{ secrets.VPN_SERVER_INTERNAL_IP }} | |
- name: Deploy | |
uses: dokku/github-action@master | |
with: | |
branch: "main" | |
git_remote_url: ssh://dokku@${{secrets.STAGING_VPN_IP}}/backend | |
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY_STAGING }} | |
git_push_flags: "--force" | |
release-chatbot-staging: | |
needs: check-changed-apps | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
if: needs.check-changed-apps.outputs.changed-files-chatbot == 'true' | |
concurrency: | |
group: wireguard | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.head_ref }} | |
fetch-depth: 0 | |
- name: Generate a new version | |
id: version | |
uses: codacy/[email protected] | |
with: | |
prefix: chatbot- | |
log-paths: chatbot/ | |
release-branch: k8s-deployment # TODO: Change to main | |
minor-identifier: "feat:" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker build | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./chatbot | |
tags: agendaodonto/chatbot:${{ steps.version.outputs.version }} | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Setup wireguard | |
uses: egor-tensin/setup-wireguard@v1 | |
with: | |
endpoint: ${{ secrets.WG_ENDPOINT }} | |
endpoint_public_key: ${{ secrets.WG_ENDPOINT_PUBLIC_KEY }} | |
private_key: ${{ secrets.WG_PRIVATE_KEY }} | |
ips: ${{ secrets.WG_IPS }} | |
allowed_ips: ${{ secrets.WG_ALLOWED_IPS }} | |
- name: Check VPN connection | |
run: ping -c1 ${{ secrets.VPN_SERVER_INTERNAL_IP }} | |
- name: Deploy | |
uses: dokku/github-action@master | |
with: | |
branch: "backend-in-docker" | |
git_remote_url: ssh://dokku@${{secrets.STAGING_VPN_IP}}/messaging | |
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY_STAGING }} | |
git_push_flags: "--force" | |
release-webapp-staging: | |
needs: check-changed-apps | |
if: needs.check-changed-apps.outputs.changed-files-webapp == 'true' | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 14 | |
cache: "npm" | |
cache-dependency-path: webapp/package-lock.json | |
- name: Build | |
run: | | |
cd webapp | |
npm ci | |
npm run build:staging | |
- name: Deploy | |
uses: FirebaseExtended/action-hosting-deploy@v0 | |
with: | |
repoToken: "${{ secrets.GITHUB_TOKEN }}" | |
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_STAGING_ACCOUNT }}" | |
projectId: agendaodontoweb-staging | |
channelId: live | |
entryPoint: ./webapp | |
firebaseToolsVersion: "11.16.1" | |
e2e-tests-staging: | |
runs-on: ubuntu-latest | |
needs: | |
[release-backend-staging, release-chatbot-staging, release-webapp-staging] | |
defaults: | |
run: | |
working-directory: webapp | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 16 | |
cache: "npm" | |
cache-dependency-path: webapp/package-lock.json | |
- name: Install dependencies | |
run: npm ci | |
- name: Install playwright browsers | |
run: npx playwright install --with-deps | |
- name: Run E2E | |
env: | |
APP_HOST: "https://staging.agendaodonto.com" | |
run: npm run test:e2e |