Merge pull request #102 from ISTTP/develop #100
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: Deploy with Docker Compose | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
inputs: | |
clear_cache: | |
description: 'Clear Docker cache? (true/false)' | |
required: false | |
default: 'false' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Cache turbo build setup | |
uses: actions/cache@v4 | |
with: | |
path: .turbo | |
key: ${{ runner.os }}-turbo-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-turbo- | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: Install pnpm | |
run: npm install -g pnpm | |
- name: install dependencies | |
run: pnpm install | |
- name: Generate Environment Variables File for Database | |
run: echo "DATABASE_URL=$DATABASE_URL" >> .env | |
working-directory: ./packages/database | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
- name: Generate Environment Variables File for Client | |
run: | | |
echo "SERVER_URL=$SERVER_URL" >> .env | |
echo "KAKAO_JAVASCRIPT_KEY=$KAKAO_JAVASCRIPT_KEY" >> .env | |
echo "FIREBASE_VAPID_KEY=$FIREBASE_VAPID_KEY" >> .env | |
echo "API_KEY=$API_KEY" >> .env | |
echo "AUTH_DOMAIN=$AUTH_DOMAIN" >> .env | |
echo "PROJECT_ID=$PROJECT_ID" >> .env | |
echo "STORAGE_BUCKET=$STORAGE_BUCKET" >> .env | |
echo "MESSAGING_SENDER_ID=$MESSAGING_SENDER_ID" >> .env | |
echo "APP_ID=$APP_ID" >> .env | |
echo "MEASUREMENT_ID=$MEASUREMENT_ID" >> .env | |
echo "PASSWORD_SALT=$PASSWORD_SALT" >> .env | |
working-directory: ./apps/client | |
env: | |
SERVER_URL: ${{ secrets.SERVER_URL }} | |
KAKAO_JAVASCRIPT_KEY: ${{ secrets.KAKAO_JAVASCRIPT_KEY }} | |
FIREBASE_VAPID_KEY: ${{ secrets.FIREBASE_VAPID_KEY }} | |
API_KEY: ${{ secrets.API_KEY }} | |
AUTH_DOMAIN: ${{ secrets.AUTH_DOMAIN }} | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
STORAGE_BUCKET: ${{ secrets.STORAGE_BUCKET }} | |
MESSAGING_SENDER_ID: ${{ secrets.MESSAGING_SENDER_ID }} | |
APP_ID: ${{ secrets.APP_ID }} | |
MEASUREMENT_ID: ${{ secrets.MEASUREMENT_ID }} | |
PASSWORD_SALT: ${{ secrets.PASSWORD_SALT }} | |
- name: Generate Environment Variables File for Server | |
run: | | |
echo "SERVER_PORT=$SERVER_PORT" >> .env | |
echo "SERVER_URL=$SERVER_URL" >> .env | |
echo "KAKAO_CLIENT_ID=$KAKAO_CLIENT_ID" >> .env | |
echo "KAKAO_REDIRECT_URI=$KAKAO_REDIRECT_URI" >> .env | |
echo "GOOGLE_CLIENT_ID=$GOOGLE_CLIENT_ID" >> .env | |
echo "GOOGLE_CLIENT_SECRET=$GOOGLE_CLIENT_SECRET" >> .env | |
echo "GOOGLE_REDIRECT_URI=$GOOGLE_REDIRECT_URI" >> .env | |
echo "CLIENT_URL=$CLIENT_URL" >> .env | |
echo "DATABASE_URL=$DATABASE_URL" >> .env | |
echo "JWT_SECRET=$JWT_SECRET" >> .env | |
echo "OPENAI_API_KEY=$OPENAI_API_KEY" >> .env | |
echo "EMAILJS_SERVICE_ID=$EMAILJS_SERVICE_ID" >> .env | |
echo "EMAILJS_TEMPLATE_ID=$EMAILJS_TEMPLATE_ID" >> .env | |
echo "EMAILJS_PWD_TEMPLATE_ID=$EMAILJS_PWD_TEMPLATE_ID" >> .env | |
echo "EMAILJS_PUBLIC_KEY=$EMAILJS_PUBLIC_KEY" >> .env | |
echo "EMAILJS_PRIVATE_KEY=$EMAILJS_PRIVATE_KEY" >> .env | |
echo "PASSWORD_SALT=$PASSWORD_SALT" >> .env | |
echo "ENVIRONMENT=$ENVIRONMENT" >> .env | |
working-directory: . | |
env: | |
SERVER_PORT: ${{ secrets.SERVER_PORT }} | |
SERVER_URL: ${{ secrets.SERVER_URL }} | |
KAKAO_CLIENT_ID: ${{ secrets.KAKAO_CLIENT_ID }} | |
KAKAO_REDIRECT_URI: ${{ secrets.KAKAO_REDIRECT_URI }} | |
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} | |
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} | |
GOOGLE_REDIRECT_URI: ${{ secrets.GOOGLE_REDIRECT_URI }} | |
CLIENT_URL: ${{ secrets.CLIENT_URL }} | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
EMAILJS_SERVICE_ID: ${{ secrets.EMAILJS_SERVICE_ID }} | |
EMAILJS_TEMPLATE_ID: ${{ secrets.EMAILJS_TEMPLATE_ID }} | |
EMAILJS_PWD_TEMPLATE_ID: ${{ secrets.EMAILJS_PWD_TEMPLATE_ID }} | |
EMAILJS_PUBLIC_KEY: ${{ secrets.EMAILJS_PUBLIC_KEY }} | |
EMAILJS_PRIVATE_KEY: ${{ secrets.EMAILJS_PRIVATE_KEY }} | |
PASSWORD_SALT: ${{ secrets.PASSWORD_SALT }} | |
ENVIRONMENT: ${{ secrets.ENVIRONMENT }} | |
- name: Create JSON file for FCM | |
env: | |
TYPE: ${{ secrets.TYPE }} | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }} | |
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | |
CLIENT_EMAIL: ${{ secrets.CLIENT_EMAIL }} | |
CLIENT_ID: ${{ secrets.CLIENT_ID }} | |
AUTH_URI: ${{ secrets.AUTH_URI }} | |
TOKEN_URI: ${{ secrets.TOKEN_URI }} | |
AUTH_PROVIDER_URL: ${{ secrets.AUTH_PROVIDER_URL }} | |
CLIENT_CERT_URL: ${{ secrets.CLIENT_CERT_URL }} | |
UNIVERSE_DOMAIN: ${{ secrets.UNIVERSE_DOMAIN }} | |
run: | | |
echo '{ | |
"type": "'"${TYPE}"'", | |
"project_id": "'"${PROJECT_ID}"'", | |
"private_key_id": "'"${PRIVATE_KEY_ID}"'", | |
"private_key": "'"${PRIVATE_KEY}"'", | |
"client_email": "'"${CLIENT_EMAIL}"'", | |
"client_id": "'"${CLIENT_ID}"'", | |
"auth_uri": "'"${AUTH_URI}"'", | |
"token_uri": "'"${TOKEN_URI}"'", | |
"auth_provider_x509_cert_url": "'"${AUTH_PROVIDER_URL}"'", | |
"client_x509_cert_url": "'"${CLIENT_CERT_URL}"'", | |
"universe_domain": "'"${UNIVERSE_DOMAIN}"'" | |
}' > ./apps/server/service-account.json | |
- name: build | |
run: pnpm turbo run build | |
- name: run unit tests | |
run: pnpm turbo run test | |
- name: run integration tests | |
run: pnpm turbo run test:integ | |
- name: download playwright browsers | |
run: pnpm exec playwright install | |
working-directory: ./apps/client | |
- name: run E2E test | |
run: pnpm turbo run test:e2e | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PW }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Prune Docker builder cache (when we want to clear cache) | |
if: ${{ github.event.inputs.clear_cache == 'true' }} | |
run: docker builder prune --all --force | |
- name: Cache Docker layers | |
uses: docker/bake-action@master | |
with: | |
push: true | |
load: true | |
files: |- | |
docker-compose.yml | |
docker-compose-cache.json | |
- name: Pull and restart Docker Container | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.SSH_KEY }} | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
script: | | |
cd ./kkoo | |
docker compose down | |
docker compose pull | |
docker compose up -d | |
docker image prune -f | |
sudo systemctl restart nginx |