diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ed8474..efd6f28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,8 @@ name: CI on: - push: - branches: ["main"] - pull_request: - branches: ["main"] + workflow_dispatch: {} + workflow_call: permissions: contents: read diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml deleted file mode 100644 index 0b4beb5..0000000 --- a/.github/workflows/fly-deploy.yml +++ /dev/null @@ -1,18 +0,0 @@ -# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ - -name: Fly Deploy -on: - push: - branches: - - main -jobs: - deploy: - name: Deploy app - runs-on: ubuntu-latest - concurrency: deploy-group # optional: ensure only one action runs at a time - steps: - - uses: actions/checkout@v4 - - uses: superfly/flyctl-actions/setup-flyctl@master - - run: flyctl deploy --remote-only - env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/fly-review.yml b/.github/workflows/fly-review.yml deleted file mode 100644 index 379ee40..0000000 --- a/.github/workflows/fly-review.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Deploy Review App -on: - # Run this workflow on every PR event. Existing review apps will be updated when the PR is updated. - pull_request: - types: [opened, reopened, synchronize, closed] - -env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - FLY_REGION: ams - FLY_ORG: personal - -jobs: - review_app: - runs-on: ubuntu-latest - outputs: - url: ${{ steps.deploy.outputs.url }} - # Only run one deployment at a time per PR. - concurrency: - group: pr-${{ github.event.number }} - - # Deploying apps with this "review" environment allows the URL for the app to be displayed in the PR UI. - # Feel free to change the name of this environment. - environment: - name: review - # The script in the `deploy` sets the URL output for each review app. - url: ${{ steps.deploy.outputs.url }} - - steps: - - name: Get code - uses: actions/checkout@v4 - - - name: Deploy PR app to Fly.io - id: deploy - uses: superfly/fly-pr-review-apps@1.2.0 diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml new file mode 100644 index 0000000..7c00c7e --- /dev/null +++ b/.github/workflows/production.yml @@ -0,0 +1,45 @@ +# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ + +name: Production CI +on: + push: + branches: + - main +jobs: + ci: + uses: ./.github/workflows/ci.yml + secrets: inherit + + deploy: + name: Deploy app + needs: ci + runs-on: ubuntu-latest + concurrency: deploy-group # optional: ensure only one action runs at a time + + environment: + name: production + + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + + - name: Set Fly secrets + run: | + flyctl secrets set \ + TOKEN_SIGNING_SECRET="$TOKEN_SIGNING_SECRET" \ + ADMIN_EMAIL="$ADMIN_EMAIL" \ + SPAZIO_SOLAZZO_EMAIL="$SPAZIO_SOLAZZO_EMAIL" \ + FRONT_OFFICE_PHONE_NUMBER="$FRONT_OFFICE_PHONE_NUMBER" \ + RESEND_API_KEY="$RESEND_API_KEY" \ + DATABASE_URL="$DATABASE_URL" + env: + TOKEN_SIGNING_SECRET: ${{ secrets.TOKEN_SIGNING_SECRET }} + ADMIN_EMAIL: ${{ secrets.ADMIN_EMAIL }} + SPAZIO_SOLAZZO_EMAIL: ${{ secrets.SPAZIO_SOLAZZO_EMAIL }} + FRONT_OFFICE_PHONE_NUMBER: ${{ secrets.FRONT_OFFICE_PHONE_NUMBER }} + RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml new file mode 100644 index 0000000..ac87dbf --- /dev/null +++ b/.github/workflows/review.yml @@ -0,0 +1,66 @@ +name: Deploy Review App +on: + # Run this workflow on every PR event. Existing review apps will be updated when the PR is updated. + pull_request: + types: [opened, reopened, synchronize, closed] + +env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + FLY_REGION: ams + FLY_ORG: personal + APP_NAME: pr-${{ github.event.pull_request.number }}-jasterv-spazio-solazzo + +jobs: + ci: + uses: ./.github/workflows/ci.yml + secrets: inherit + + review_app: + runs-on: ubuntu-latest + needs: ci + outputs: + url: ${{ steps.deploy.outputs.url }} + # Only run one deployment at a time per PR. + concurrency: + group: pr-${{ github.event.number }} + + # Deploying apps with this "review" environment allows the URL for the app to be displayed in the PR UI. + # Feel free to change the name of this environment. + environment: + name: review + # The script in the `deploy` sets the URL output for each review app. + url: ${{ steps.deploy.outputs.url }} + + steps: + - name: Get code + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Install flyctl CLI + uses: superfly/flyctl-actions/setup-flyctl@master + - name: Authenticate with Fly.io registry + run: flyctl auth docker + - name: Create Fly App before pushing docker image to registry + run: | + flyctl apps create ${{ env.APP_NAME }} --org ${{ env.FLY_ORG }} || true + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + push: true + tags: registry.fly.io/${{ env.APP_NAME }}:1.19 + context: . + - name: Deploy PR app to Fly.io + id: deploy + uses: superfly/fly-pr-review-apps@1.5.0 + with: + name: ${{ env.APP_NAME }} + config: fly.review.toml + secrets: | + TOKEN_SIGNING_SECRET=${{ secrets.TOKEN_SIGNING_SECRET }} + ADMIN_EMAIL=${{ secrets.ADMIN_EMAIL }} + SPAZIO_SOLAZZO_EMAIL=${{ secrets.SPAZIO_SOLAZZO_EMAIL }} + FRONT_OFFICE_PHONE_NUMBER=${{ secrets.FRONT_OFFICE_PHONE_NUMBER }} + RESEND_API_KEY=${{ secrets.RESEND_API_KEY }} + DATABASE_URL=${{ secrets.DATABASE_URL }} + SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }} + PHX_HOST=${{ env.APP_NAME }}.fly.dev diff --git a/config/runtime.exs b/config/runtime.exs index ce96306..f048cfb 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -54,7 +54,9 @@ else You can generate one by calling: mix phx.gen.secret """ - host = System.get_env("PHX_HOST") || "example.com" + host = + System.get_env("PHX_HOST") || + raise "Missing environment variable `PHX_HOST`!" config :spazio_solazzo, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") diff --git a/fly.review.toml b/fly.review.toml new file mode 100644 index 0000000..3f8b1ce --- /dev/null +++ b/fly.review.toml @@ -0,0 +1,34 @@ +# fly.review.toml +# +app = "spazio-solazzo" +primary_region = "ams" +kill_signal = "SIGTERM" + +[build] + +[deploy] +release_command = '/app/bin/migrate' +wait_timeout = "10m" + +[env] +PHX_SERVER = "true" +PORT = "8080" + +[http_service] +internal_port = 8080 +force_https = true +auto_stop_machines = 'stop' +auto_start_machines = true +min_machines_running = 0 +processes = ["app"] + +[http_service.concurrency] +type = "connections" +soft_limit = 500 +hard_limit = 500 + +[[vm]] +cpu_kind = "shared" +memory = '512mb' +cpus = 1 +memory_mb = 512 diff --git a/fly.toml b/fly.toml index b24a8ae..f616476 100644 --- a/fly.toml +++ b/fly.toml @@ -8,6 +8,7 @@ primary_region = 'ams' kill_signal = 'SIGTERM' [build] +dockerfile = "Dockerfile" [deploy] release_command = '/app/bin/migrate' diff --git a/lib/spazio_solazzo_web/components/layouts.ex b/lib/spazio_solazzo_web/components/layouts.ex index 60b17c4..d5c076f 100644 --- a/lib/spazio_solazzo_web/components/layouts.ex +++ b/lib/spazio_solazzo_web/components/layouts.ex @@ -39,7 +39,7 @@ defmodule SpazioSolazzoWeb.Layouts do def app(assigns) do ~H""" - <.app_header current_user={@current_user} /> + <.app_header current_user={@current_user} title="Spazio Solazzo" icon="hero-sun-solid" />
{render_slot(@inner_block)} @@ -116,19 +116,26 @@ defmodule SpazioSolazzoWeb.Layouts do """ end + attr :title, :string, default: nil, doc: "the title shown on the top left of the header" + attr :icon, :string, default: nil, doc: "The icon shown on the top left of the header" + + attr :current_user, :map, + default: nil, + doc: "the current authenticated user" + defp app_header(assigns) do ~H"""
<.link navigate="/" - class="flex items-center gap-4 text-slate-900 dark:text-slate-100 hover:opacity-80 transition-opacity" + class="flex items-center gap-3 text-slate-900 dark:text-slate-100 hover:opacity-80 transition-opacity" > -
- <.icon name="hero-squares-2x2" class="size-5" /> +
+ <.icon name={@icon} class="size-8" />

- Spazio Solazzo + {@title}