Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test docker #2642

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
954a46e
add dockerignore
raulfdm Dec 2, 2023
26fa161
add docker images
raulfdm Dec 2, 2023
4e2f05a
replace adapter to be nodejs
raulfdm Dec 2, 2023
186a06c
update lock file
raulfdm Dec 2, 2023
6cb1aa7
move astro node to prod dependency
raulfdm Dec 2, 2023
7229f16
temp dockerfile
raulfdm Dec 2, 2023
ace7c1e
fix docker
raulfdm Dec 3, 2023
5e9933d
update bun-types
raulfdm Dec 3, 2023
589883d
make base docker image flexible
raulfdm Dec 3, 2023
91f3fd6
remove temp vite config
raulfdm Dec 3, 2023
65b771a
update docker image
raulfdm Dec 3, 2023
c83c9c2
refactor how to use environment variables
raulfdm Dec 3, 2023
8b811f8
add more stuff to docker
raulfdm Dec 3, 2023
fc52311
fix turbo
raulfdm Dec 3, 2023
db325c8
Update build script to use docker buildx
raulfdm Dec 3, 2023
8dc602a
Refactor build dependencies and outputs in
raulfdm Dec 3, 2023
481cd34
test v2 docker file
raulfdm Dec 3, 2023
78f6174
tweak docker filter
raulfdm Dec 3, 2023
d5bac8a
remove host
raulfdm Dec 3, 2023
1991d60
change website CI
raulfdm Dec 3, 2023
e8b7de5
fix paths
raulfdm Dec 3, 2023
90aea5d
add fly toml
raulfdm Dec 3, 2023
7a9af0b
add website deploy
raulfdm Dec 3, 2023
b557431
fix test label
raulfdm Dec 3, 2023
476d1df
fix version
raulfdm Dec 3, 2023
2e1f9df
ignore out folder
raulfdm Dec 3, 2023
03db240
Update .dockerignore file
raulfdm Dec 3, 2023
01450c5
fix build website
raulfdm Dec 3, 2023
6c56805
change docker file
raulfdm Dec 3, 2023
99cec6b
change devDependencies
raulfdm Dec 4, 2023
e69b118
update pnpm lock
raulfdm Dec 4, 2023
272a4ec
tweak dev dependencies
raulfdm Dec 4, 2023
9b5b549
update docker image
raulfdm Dec 4, 2023
643b29f
enhance install
raulfdm Dec 4, 2023
dd89feb
add build-target to fly toml
raulfdm Dec 4, 2023
7c5230a
fix missing dependency
raulfdm Dec 4, 2023
e327193
tweaks
raulfdm Dec 4, 2023
6b6f81a
change cli
raulfdm Dec 4, 2023
0e93c8a
use env vars
raulfdm Dec 4, 2023
f9e98cc
remove --remote-only
raulfdm Dec 4, 2023
cb993da
change different strategy
raulfdm Dec 4, 2023
b90f0f0
comment out for now strategy
raulfdm Dec 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.git
**/node_modules
**/dist
**/.vercel
**/.svelte-kit
**/*.typegen.ts
**/.turbo/
.vscode
out
**/Dockerfile
.dockerignore
.github
.history
scripts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Website
name: Website - CI

on:
push:
paths:
- .github/workflows/website.yml
- .github/workflows/website-ci.yml
- .github/actions/pnpm-bun-setup/action.yml
- apps/website/**
- packages/**
Expand All @@ -18,13 +18,9 @@ jobs:
- name: Setup environment
uses: ./.github/actions/pnpm-bun-setup

# I don't need to add build check because this project will be build in Vercel's infrastructure.
# If something went wrong while building it, then it will fail there.

- name: Prepare website to be lint # Needed to be able to run lint propely
- name: Build
run: |
pnpm run build --filter=website^...
pnpm run typegen --filter=website
pnpm run build --filter=website

- name: Lint Projects
run: pnpm run lint --filter website
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/website-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Website - Deploy

on:
push:
branches:
- main
- test-docker

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Git files setup
uses: actions/checkout@v4

- name: Setup fly
uses: superfly/flyctl-actions/setup-flyctl@master
with:
version: 0.1.131

- run: flyctl deploy
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
ALGOLIA_ADMIN_KEY: ${{secrets.ALGOLIA_ADMIN_KEY}}
API_TOKEN: ${{secrets.API_TOKEN}}
APP_ENV: production
PUBLIC_ALGOLIA_APP_ID: ${{secrets.PUBLIC_ALGOLIA_APP_ID}}
PUBLIC_ALGOLIA_INDEX_NAME: ${{secrets.PUBLIC_ALGOLIA_INDEX_NAME}}
PUBLIC_ALGOLIA_SEARCH_KEY: ${{secrets.PUBLIC_ALGOLIA_SEARCH_KEY}}
SANITY_TOKEN: ${{secrets.SANITY_TOKEN}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ coverage

.turbo/
**/tsconfig.tsbuildinfo
**/tsconfig.*.tsbuildinfo
**/tsconfig.*.tsbuildinfo
out
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
auto-install-peers=true
strict-peer-dependencies=false
prefer-offline=true
save-prefix=''
save-prefix=''
child-concurrency=15
2 changes: 1 addition & 1 deletion apps/twin-xls-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"autoprefixer": "10.4.16",
"bun-types": "1.0.14",
"bun-types": "1.0.15",
"daisyui": "2.52.0",
"eslint": "8.54.0",
"eslint-config-prettier": "9.0.0",
Expand Down
45 changes: 45 additions & 0 deletions apps/website/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM raulfdm/website-base-image:1.0.15-8.11.0-node18 AS base

# --------------------------- #
FROM base AS builder
WORKDIR /app

COPY . .
RUN pnpm turbo prune website --docker

# --------------------------- #
FROM base as installer
WORKDIR /app

COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install --ignore-scripts

COPY --from=builder /app/out/full/ .
RUN pnpm run build

# --------------------------- #
FROM base AS runner
WORKDIR /app

COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=installer /app/apps/website/dist ./apps/website/dist
COPY --from=installer /app/packages/code-highlight/dist ./packages/code-highlight/dist
COPY --from=installer /app/packages/core/dist ./packages/core/dist
COPY --from=installer /app/packages/sanity-core/dist ./packages/sanity-core/dist

RUN pnpm install --prod --ignore-scripts

EXPOSE 4321

ENV PUBLIC_ALGOLIA_INDEX_NAME=$PUBLIC_ALGOLIA_INDEX_NAME
ENV PUBLIC_ALGOLIA_INDEX_NAME=$PUBLIC_ALGOLIA_INDEX_NAME
ENV PUBLIC_ALGOLIA_SEARCH_KEY=$PUBLIC_ALGOLIA_SEARCH_KEY
ENV PUBLIC_ALGOLIA_APP_ID=$PUBLIC_ALGOLIA_APP_ID
ENV ALGOLIA_ADMIN_KEY=$ALGOLIA_ADMIN_KEY
ENV SANITY_TOKEN=$SANITY_TOKEN
ENV API_TOKEN=$API_TOKEN
ENV APP_ENV=$APP_ENV

CMD pnpm -F website run start
57 changes: 20 additions & 37 deletions apps/website/astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import node from '@astrojs/node';
import partytown from '@astrojs/partytown';
import react from '@astrojs/react';
import svelte from '@astrojs/svelte';
import tailwind from '@astrojs/tailwind';
import vercel from '@astrojs/vercel/serverless';
import { defineConfig, sharpImageService } from 'astro/config';
import robotsTxt from 'astro-robots-txt';
import { resolve } from 'import-meta-resolve';
import { loadEnv } from 'vite';

const { VERCEL_ENV, VERCEL_URL } = loadEnv(
import.meta.env.MODE,
process.cwd(),
``,
);
// const { VERCEL_ENV, VERCEL_URL } = loadEnv(
// import.meta.env.MODE,
// process.cwd(),
// ``,
// );

const assetsDomains: string[] = [
`res.cloudinary.com`,
Expand All @@ -22,15 +21,10 @@ const assetsDomains: string[] = [
`sanity.io`,
];

const vscodeOnigurumaPath = new URL(
`onig.wasm`,
resolve(`vscode-oniguruma`, import.meta.url),
).pathname;

const config = defineConfig({
prefetch: true,
site: getWebsiteUrl(),
output: `server`,
site: 'http://localhost:4321',
// site: getWebsiteUrl(),
redirects: {
'/uses': '/en/blog/uses',
'/pt/uses': '/pt/blog/uses',
Expand All @@ -55,20 +49,9 @@ const config = defineConfig({
}),
svelte(),
],
adapter: vercel({
functionPerRoute: false,
webAnalytics: {
enabled: true,
},
speedInsights: {
enabled: true,
},
includeFiles: [vscodeOnigurumaPath],
imageService: true,
imagesConfig: {
domains: assetsDomains,
sizes: [320, 640, 768, 1024, 1280],
},
output: `server`,
adapter: node({
mode: 'standalone',
}),
vite: {
ssr: {
Expand All @@ -77,14 +60,14 @@ const config = defineConfig({
},
});

function getWebsiteUrl() {
if (VERCEL_ENV === `production`) {
return `https://www.raulmelo.me`;
} else if (VERCEL_URL) {
return `https://${VERCEL_URL}`;
} else {
return `http://localhost:4321`;
}
}
// function getWebsiteUrl() {
// if (VERCEL_ENV === `production`) {
// return `https://www.raulmelo.me`;
// } else if (VERCEL_URL) {
// return `https://${VERCEL_URL}`;
// } else {
// return `http://localhost:4321`;
// }
// }

export default config;
67 changes: 32 additions & 35 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"prepare": "turbo run typegen --filter website --output-logs errors-only",
"dev": "astro dev",
"start": "astro dev",
"start": "HOST=0.0.0.0 PORT=8080 bun ./dist/server/entry.mjs",
"build": "astro build",
"typegen": "xstate typegen \"src/**/*.ts?(x)\"",
"preview": "astro preview",
Expand All @@ -17,22 +17,13 @@
"lint:eslint": "eslint src"
},
"dependencies": {
"@astrojs/check": "0.3.1",
"@astrojs/partytown": "2.0.2",
"@astrojs/react": "3.0.6",
"@astrojs/rss": "3.0.0",
"@astrojs/svelte": "4.0.4",
"@astrojs/tailwind": "5.0.2",
"@astrojs/ts-plugin": "1.3.1",
"@astrojs/vercel": "5.2.0",
"@fontsource/fira-code": "5.0.15",
"@fontsource/inter": "5.0.15",
"@formatjs/intl": "2.9.9",
"@formatjs/intl-localematcher": "0.5.2",
"@popperjs/core": "2.11.8",
"@raulmelo/code-highlight": "workspace:*",
"@raulmelo/core": "workspace:*",
"@raulmelo/eslint-config": "workspace:*",
"@raulmelo/sanity-core": "workspace:*",
"@raulmelo/styles": "workspace:*",
"@rgossiaux/svelte-headlessui": "2.0.0",
Expand All @@ -41,33 +32,14 @@
"@sanity/vision": "3.20.1",
"@tabler/icons-react": "2.42.0",
"@tabler/icons-svelte": "2.42.0",
"@types/flat": "5.0.5",
"@types/lodash.defaultsdeep": "4.6.9",
"@types/negotiator": "0.6.3",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.17",
"@typescript-eslint/parser": "6.12.0",
"@xstate/cli": "0.5.11",
"@xstate/svelte": "3.0.0",
"algoliasearch": "4.20.0",
"astro": "3.6.4",
"astro-portabletext": "0.9.6",
"astro-robots-txt": "1.0.0",
"astro-seo": "0.8.0",
"clsx": "2.0.0",
"eslint": "8.54.0",
"eslint-plugin-astro": "0.29.1",
"flat": "6.0.1",
"humanize-string": "3.0.0",
"import-meta-resolve": "3.1.1",
"lodash.defaultsdeep": "4.6.1",
"motion": "10.16.4",
"negotiator": "0.6.3",
"npm-run-all": "4.1.5",
"postcss-load-config": "4.0.2",
"prettier": "3.0.3",
"prettier-plugin-astro": "0.12.2",
"prettier-plugin-svelte": "3.0.3",
"query-string": "8.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -82,17 +54,42 @@
"svelte-popperjs": "1.3.2",
"sveltekit-embed": "0.0.12",
"tailwind-merge": "2.0.0",
"tailwindcss": "3.3.5",
"tiny-invariant": "1.3.1",
"type-fest": "4.6.0",
"typescript": "5.2.2",
"vite": "4.5.0",
"vscode-oniguruma": "2.0.1",
"web-vitals": "3.5.0",
"xstate": "5.0.0",
"zod": "3.22.4",
"zod-validation-error": "2.0.0"
},
"devDependencies": {
"@astrojs/check": "0.3.1",
"@astrojs/node": "6.1.0",
"@astrojs/partytown": "2.0.2",
"@astrojs/react": "3.0.6",
"@astrojs/rss": "3.0.0",
"@astrojs/svelte": "4.0.4",
"@astrojs/tailwind": "5.0.2",
"@astrojs/ts-plugin": "1.3.1",
"@raulmelo/eslint-config": "workspace:*",
"@types/flat": "5.0.5",
"@types/negotiator": "0.6.3",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.17",
"@typescript-eslint/parser": "6.12.0",
"@xstate/cli": "0.5.11",
"astro": "3.6.4",
"astro-robots-txt": "1.0.0",
"astro-seo": "0.8.0",
"eslint": "8.54.0",
"eslint-plugin-astro": "0.29.1",
"npm-run-all": "4.1.5",
"postcss-load-config": "4.0.2",
"prettier": "3.0.3",
"prettier-plugin-astro": "0.12.2",
"prettier-plugin-svelte": "3.0.3",
"tailwindcss": "3.3.5",
"type-fest": "4.6.0",
"typescript": "5.2.2",
"vite": "4.5.0"
},
"engines": {
"node": "18",
"pnpm": "8"
Expand Down
4 changes: 3 additions & 1 deletion apps/website/src/infrastructure/env/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const clientEnvSchema = z.object({
PUBLIC_VERCEL_ANALYTICS_ID: z.string().optional(),
});

export const clientEnv = clientEnvSchema.parse(import.meta.env);
export function getClientEnv() {
return clientEnvSchema.parse(import.meta.env);
}
4 changes: 3 additions & 1 deletion apps/website/src/infrastructure/env/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ const serverEnvSchema = z.object({
API_TOKEN: z.string(),
});

export const serverEnv = serverEnvSchema.parse(import.meta.env);
export function getServerEnv() {
return serverEnvSchema.parse(import.meta.env);
}
24 changes: 14 additions & 10 deletions apps/website/src/infrastructure/sanity/client.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { createClient } from '@sanity/client';

import { serverEnv } from '../env/server';
import { getServerEnv } from '../env/server';
import { config } from './config';

export const sanityClient = createClient({
dataset: config.dataset,
projectId: config.projectId,
apiVersion: `v2021-10-21`,
perspective: 'published',
useCdn: true,
token: serverEnv.SANITY_TOKEN,
allowReconfigure: true,
});
export function getSanityClient() {
const serverEnv = getServerEnv();

return createClient({
dataset: config.dataset,
projectId: config.projectId,
apiVersion: `v2021-10-21`,
perspective: 'published',
useCdn: true,
token: serverEnv.SANITY_TOKEN,
allowReconfigure: true,
});
}
Loading