From d001fba76496a306006088c57fd6e44beaedfefc Mon Sep 17 00:00:00 2001 From: m5r Date: Mon, 27 Jun 2022 02:26:06 +0200 Subject: [PATCH] deploy that shit --- .dockerignore | 2 +- .github/workflows/main.yml | 74 ++++++++++++-------------------- Dockerfile | 2 +- app/config/config.server.ts | 7 --- app/utils/twilio.server.ts | 6 +-- fly.dev.toml | 53 +++++++++++++++++++++++ fly.redis.toml | 8 ++-- fly.toml | 85 ++++++++++++++++++------------------- 8 files changed, 131 insertions(+), 106 deletions(-) create mode 100644 fly.dev.toml diff --git a/.dockerignore b/.dockerignore index df91955..29ff348 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,4 +9,4 @@ node_modules /.cache /public/build /build -server.js \ No newline at end of file +/server/index.js \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 71ee2cb..f9c2116 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,53 +15,9 @@ jobs: - run: npm ci - run: npm run lint - e2e: - name: E2E tests - runs-on: ubuntu-latest - services: - postgres: - image: postgres:13-alpine - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - env: - POSTGRES_USER: pgremixtape - POSTGRES_PASSWORD: pgpassword - POSTGRES_DB: remixtape - ports: - - "5432:5432" - redis: - image: redis:6-alpine - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - "6379:6379" - env: - DATABASE_URL: postgresql://pgremixtape:pgpassword@localhost:5432/remixtape - REDIS_URL: redis://localhost:6379 - CI: true - steps: - - uses: actions/checkout@v2 - - run: cp .env.example .env - - uses: actions/setup-node@v2 - with: - node-version: 16 - cache: "npm" - - run: npm ci - - run: npm run db:setup - - run: npm run build - - run: npx dotenv npm run e2e:ci - typecheck: name: Typecheck runs-on: ubuntu-latest - env: - HUSKY_SKIP_INSTALL: 1 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -70,10 +26,29 @@ jobs: - run: npm ci - run: npx tsc - deploy: + deploy_development: if: github.ref == 'refs/heads/master' - needs: [lint, e2e, typecheck] - name: Deploy to Fly.io + needs: [lint, typecheck] + name: Deploy development environment + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: superfly/flyctl-actions@master + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + with: + args: "deploy --strategy rolling -c ./fly.dev.toml" + - uses: appleboy/discord-action@master + with: + webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} + webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} + args: "https://dev.shellphone.app deployed with commit `${{ github.event.head_commit.message }}` (`${{ github.sha }}`) from branch `${{ github.ref }}`" + + + deploy_production: + if: github.ref == 'refs/heads/production' + needs: [lint, typecheck] + name: Deploy production environment runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -82,3 +57,8 @@ jobs: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} with: args: "deploy --strategy rolling" + - uses: appleboy/discord-action@master + with: + webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} + webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} + args: "https://www.shellphone.app deployed with commit `${{ github.event.head_commit.message }}` (`${{ github.sha }}`) from branch `${{ github.ref }}`" diff --git a/Dockerfile b/Dockerfile index 080f4ad..a615be1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ COPY --from=production-deps /app/node_modules /app/node_modules COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma COPY --from=build /app/build /app/build COPY --from=build /app/public /app/public -COPY --from=build /app/server.js /app/server.js +COPY --from=build /app/server/index.js /app/server/index.js ADD . . CMD ["npm", "run", "start"] diff --git a/app/config/config.server.ts b/app/config/config.server.ts index 86c87fd..53e9ddd 100644 --- a/app/config/config.server.ts +++ b/app/config/config.server.ts @@ -20,10 +20,6 @@ invariant( `Please define the "AWS_SES_FROM_EMAIL" environment variable`, ); invariant(typeof process.env.REDIS_URL === "string", `Please define the "REDIS_URL" environment variable`); -invariant( - typeof process.env.TWILIO_AUTH_TOKEN === "string", - `Please define the "TWILIO_AUTH_TOKEN" environment variable`, -); invariant( typeof process.env.MASTER_ENCRYPTION_KEY === "string", `Please define the "MASTER_ENCRYPTION_KEY" environment variable`, @@ -65,9 +61,6 @@ export default { sentry: { dsn: process.env.SENTRY_DSN, }, - twilio: { - authToken: process.env.TWILIO_AUTH_TOKEN, - }, webPush: { privateKey: process.env.WEB_PUSH_VAPID_PRIVATE_KEY, publicKey: process.env.WEB_PUSH_VAPID_PUBLIC_KEY, diff --git a/app/utils/twilio.server.ts b/app/utils/twilio.server.ts index e610d07..d751909 100644 --- a/app/utils/twilio.server.ts +++ b/app/utils/twilio.server.ts @@ -23,11 +23,11 @@ export const voiceUrl = `${serverConfig.app.baseUrl}/webhook/call`; export function getTwiMLName() { switch (serverConfig.app.baseUrl) { - case "local.shellphone.app": + case "https://local.shellphone.app": return "Shellphone LOCAL"; - case "dev.shellphone.app": + case "https://dev.shellphone.app": return "Shellphone DEV"; - case "www.shellphone.app": + case "https://www.shellphone.app": return "Shellphone"; } } diff --git a/fly.dev.toml b/fly.dev.toml new file mode 100644 index 0000000..4f6d337 --- /dev/null +++ b/fly.dev.toml @@ -0,0 +1,53 @@ +app = "shellphone-dev" +kill_signal = "SIGINT" +kill_timeout = 5 +processes = [] + +[deploy] + release_command = "npx prisma migrate deploy" + +[env] + APP_BASE_URL = "https://dev.shellphone.app" + AWS_SES_FROM_EMAIL = "\"Mokhtar from Shellphone\" " + AWS_SES_REGION = "eu-central-1" + NODE_ENV = "production" + PORT = "8080" + +[experimental] + allowed_public_ports = [] + auto_rollback = true + +[[services]] + internal_port = 8080 + processes = ["app"] + protocol = "tcp" + script_checks = [] + [services.concurrency] + hard_limit = 25 + soft_limit = 20 + type = "connections" + + [[services.http_checks]] + grace_period = "5s" + interval = 10000 + method = "get" + path = "/healthcheck" + protocol = "http" + timeout = 2000 + tls_skip_verify = false + [services.http_checks.headers] + + [[services.ports]] + force_https = true + handlers = ["http"] + port = 80 + + [[services.ports]] + handlers = ["tls", "http"] + port = 443 + + [[services.tcp_checks]] + grace_period = "1s" + interval = "15s" + restart_limit = 0 + timeout = "2s" diff --git a/fly.redis.toml b/fly.redis.toml index b809308..1a9c9a7 100644 --- a/fly.redis.toml +++ b/fly.redis.toml @@ -1,18 +1,18 @@ -app = "shellphoneappremixed-redis" +app = "shellphone-redis" kill_signal = "SIGINT" kill_timeout = 5 -processes = [ ] +processes = [] [build] image = "flyio/redis:6.2.6" [experimental] -allowed_public_ports = [ ] +allowed_public_ports = [] auto_rollback = true [[mounts]] destination = "/data" -source = "shellphoneappremixed_redis_data" +source = "shellphone_redis_data" [metrics] port = 9_091 diff --git a/fly.toml b/fly.toml index d57896d..37da5f7 100644 --- a/fly.toml +++ b/fly.toml @@ -1,54 +1,53 @@ -app = "shellphoneappremixed" +app = "shellphone-prod" kill_signal = "SIGINT" kill_timeout = 5 -processes = [ ] - -[env] -APP_BASE_URL = "https://shellphoneappremixed.fly.dev" -AWS_SES_FROM_EMAIL = "remixtape@fake.app" -AWS_SES_REGION = "eu-central-1" -NODE_ENV = "production" -PORT = "8080" +processes = [] [deploy] -release_command = "npx prisma migrate deploy" + release_command = "npx prisma migrate deploy" + +[env] + APP_BASE_URL = "https://www.shellphone.app" + AWS_SES_FROM_EMAIL = "\"Mokhtar from Shellphone\" " + AWS_SES_REGION = "eu-central-1" + NODE_ENV = "production" + PORT = "8080" [experimental] -allowed_public_ports = [ ] -auto_rollback = true + allowed_public_ports = [] + auto_rollback = true [[services]] -internal_port = 8_080 -processes = [ "app" ] -protocol = "tcp" -script_checks = [ ] - + internal_port = 8080 + processes = ["app"] + protocol = "tcp" + script_checks = [] [services.concurrency] - hard_limit = 25 - soft_limit = 20 - type = "connections" - - [[services.ports]] - handlers = [ "http" ] - port = 80 - force_https = true - - [[services.ports]] - handlers = [ "tls", "http" ] - port = 443 - - [[services.tcp_checks]] - grace_period = "1s" - interval = "15s" - restart_limit = 0 - timeout = "2s" + hard_limit = 25 + soft_limit = 20 + type = "connections" [[services.http_checks]] - interval = 10_000 - grace_period = "5s" - method = "get" - path = "/healthcheck" - protocol = "http" - timeout = 2_000 - tls_skip_verify = false - headers = { } + grace_period = "5s" + interval = 10000 + method = "get" + path = "/healthcheck" + protocol = "http" + timeout = 2000 + tls_skip_verify = false + [services.http_checks.headers] + + [[services.ports]] + force_https = true + handlers = ["http"] + port = 80 + + [[services.ports]] + handlers = ["tls", "http"] + port = 443 + + [[services.tcp_checks]] + grace_period = "1s" + interval = "15s" + restart_limit = 0 + timeout = "2s"