From 5305253f4a8ff8d513a9fe7bf47e1cf42cf2f2c1 Mon Sep 17 00:00:00 2001 From: Luis Roel Date: Tue, 3 Dec 2024 11:17:26 -0800 Subject: [PATCH 1/3] deploys but images not linking due to vercel adapter --- .dockerignore | 26 +++++++++++++++++ .github/workflows/fly-deploy.yml | 18 ++++++++++++ Dockerfile | 50 ++++++++++++++++++++++++++++++++ astro.config.ts | 18 +++++------- fly.toml | 22 ++++++++++++++ nginx.conf | 17 +++++++++++ package.json | 3 ++ pnpm-lock.yaml | 11 ++++++- 8 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/fly-deploy.yml create mode 100644 Dockerfile create mode 100644 fly.toml create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..d83d46e7c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +# build output +dist/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store +.idea/ +.eslintcache +.vercel +.puppeteer + +.astro +.gitignore diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 000000000..b0c246ede --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,18 @@ +# 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/Dockerfile b/Dockerfile new file mode 100644 index 000000000..47e63216d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM node:20.11-slim as dependencies +WORKDIR /app + +# Install pnpm and build dependencies +RUN npm install -g pnpm@9.4.0 && \ + apt-get update -qq && \ + apt-get install -y python3 build-essential && \ + rm -rf /var/lib/apt/lists/* + +# Create the environments directory and env file FIRST +RUN mkdir -p src/environments && \ + echo "PLAYWRIGHT_BROWSERS_PATH=/app/pw-browsers" > src/environments/browser-path.env + +# Copy package files +COPY package.json pnpm-lock.yaml ./ + +# Install dependencies and extra packages needed for content generation +ENV PLAYWRIGHT_BROWSERS_PATH=/app/pw-browsers +ENV HUSKY=0 +RUN pnpm install && \ + pnpm playwright install chromium + +# Content generation stage +FROM dependencies as content-builder +WORKDIR /app + +# Copy source files +COPY . . + +# Copy over the node_modules and Playwright browsers +COPY --from=dependencies /app/node_modules ./node_modules +COPY --from=dependencies /app/pw-browsers ./pw-browsers +COPY --from=dependencies /app/src/environments/browser-path.env ./src/environments/browser-path.env + +# First generate the content +RUN pnpm run epub & pnpm run social-previews:build & wait + +# Run just the Astro build +RUN pnpm exec astro build --experimental-integrations || if [ -d "dist" ]; then \ + exit 0; \ + else \ + exit 1; \ + fi + +# Production stage for static files +FROM nginx:alpine +COPY --from=content-builder /app/dist /usr/share/nginx/html + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/astro.config.ts b/astro.config.ts index 0d49c8b7a..792b93f7c 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -4,7 +4,6 @@ import sitemap from "@astrojs/sitemap"; import icon from "astro-icon"; import { EnumChangefreq as ChangeFreq } from "sitemap"; import { siteUrl } from "./src/constants/site-config"; -import vercel from "@astrojs/vercel"; import symlink from "symlink-dir"; import * as path from "path"; import { languages } from "./src/constants/index"; @@ -18,16 +17,15 @@ await symlink(path.resolve("content"), path.resolve("public/content")); export default defineConfig({ site: siteUrl, - adapter: vercel({ - // Uses Vercel's Image Optimization API: https://vercel.com/docs/image-optimization - imageService: true, - imagesConfig: { - sizes: SUPPORTED_IMAGE_SIZES, - domains: [], - formats: ["image/avif", "image/webp"], + output: "static", + image: { + service: { + entrypoint: "astro/assets/services/sharp", + config: { + limitInputPixels: false, + }, }, - devImageService: "sharp", - }), + }, integrations: [ icon(), preact({ compat: true }), diff --git a/fly.toml b/fly.toml new file mode 100644 index 000000000..322e20da7 --- /dev/null +++ b/fly.toml @@ -0,0 +1,22 @@ +# fly.toml app configuration file generated for playfulprogramming-bak on 2024-12-02T18:59:27-08:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'playfulprogramming-bak' +primary_region = 'sjc' + +[build] + dockerfile = 'Dockerfile' + +[http_service] + internal_port = 80 + force_https = true + auto_stop_machines = 'stop' + auto_start_machines = true + min_machines_running = 0 + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 000000000..a07beb32e --- /dev/null +++ b/nginx.conf @@ -0,0 +1,17 @@ +server { + listen 80; + root /usr/share/nginx/html; + index index.html; + etag on; + + location / { + try_files $uri $uri/ /index.html; + add_header Cache-Control "no-cache"; + } + + # Cache static assets + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { + expires 1y; + add_header Cache-Control "public, no-transform"; + } +} \ No newline at end of file diff --git a/package.json b/package.json index d01312238..964e93a39 100644 --- a/package.json +++ b/package.json @@ -90,11 +90,13 @@ "hast-util-heading-rank": "^3.0.0", "hast-util-to-string": "^3.0.0", "hastscript": "^9.0.0", + "html-escaper": "^3.0.3", "husky": "^9.0.11", "identity-obj-proxy": "^3.0.0", "jest-location-mock": "^2.0.0", "json5": "^2.2.3", "junk": "^4.0.1", + "kleur": "^4.1.5", "lint-staged": "^15.2.7", "live-server": "^1.2.2", "lru-cache": "^11.0.2", @@ -110,6 +112,7 @@ "prettier-plugin-astro": "^0.14.1", "react": "npm:@preact/compat@17.1.2", "react-dom": "npm:@preact/compat@17.1.2", + "rehype-parse": "9.0.0", "rehype-raw": "^7.0.0", "rehype-slug-custom-id": "^2.0.0", "rehype-stringify": "^10.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ce634aece..827dda1de 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -178,6 +178,9 @@ importers: hastscript: specifier: ^9.0.0 version: 9.0.0 + html-escaper: + specifier: ^3.0.3 + version: 3.0.3 husky: specifier: ^9.0.11 version: 9.0.11 @@ -193,6 +196,9 @@ importers: junk: specifier: ^4.0.1 version: 4.0.1 + kleur: + specifier: ^4.1.5 + version: 4.1.5 lint-staged: specifier: ^15.2.7 version: 15.2.7 @@ -238,6 +244,9 @@ importers: react-dom: specifier: npm:@preact/compat@17.1.2 version: '@preact/compat@17.1.2(preact@10.23.2)' + rehype-parse: + specifier: 9.0.0 + version: 9.0.0 rehype-raw: specifier: ^7.0.0 version: 7.0.0 @@ -7746,7 +7755,7 @@ snapshots: fs-extra: 11.2.0 image-size: 1.1.1 mime: 4.0.3 - rehype-parse: 9.0.0 + rehype-parse: 9.0.1 rehype-stringify: 10.0.0 unified: 11.0.5 unist-util-visit: 5.0.0 From 30ae838fc4258817ea4422a8b9db0ad5bb70c872 Mon Sep 17 00:00:00 2001 From: Luis Roel Date: Fri, 13 Dec 2024 15:34:27 -0800 Subject: [PATCH 2/3] Enabled preview deploys --- .github/workflows/fly-review.yml | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/fly-review.yml diff --git a/.github/workflows/fly-review.yml b/.github/workflows/fly-review.yml new file mode 100644 index 000000000..41da34e70 --- /dev/null +++ b/.github/workflows/fly-review.yml @@ -0,0 +1,35 @@ +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 }} + # Set these to your Fly.io organization and preferred region. + FLY_REGION: iad + FLY_ORG: playful-programming + +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 \ No newline at end of file From b65f5d2581c52fc9e4383c75007fc0f15c83392f Mon Sep 17 00:00:00 2001 From: Luis Roel Date: Fri, 13 Dec 2024 15:44:47 -0800 Subject: [PATCH 3/3] Added env cleanup --- .github/workflows/fly-review.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fly-review.yml b/.github/workflows/fly-review.yml index 41da34e70..f302191c6 100644 --- a/.github/workflows/fly-review.yml +++ b/.github/workflows/fly-review.yml @@ -32,4 +32,11 @@ jobs: - name: Deploy PR app to Fly.io id: deploy - uses: superfly/fly-pr-review-apps@1.2.0 \ No newline at end of file + uses: superfly/fly-pr-review-apps@1.2.0 + + - name: Clean up preview environment + uses: strumwolf/delete-deployment-environment@v2 + if: ${{ github.event.action == 'closed' }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: pr-${{ github.event.number }} \ No newline at end of file