Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 authored Mar 4, 2023
2 parents 5501c9b + 25591a0 commit e374f14
Show file tree
Hide file tree
Showing 17 changed files with 386 additions and 150 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
OPENAI_API_KEY=
# Your API Key for OpenAI
OPENAI_API_KEY=
# Provide proxy for OpenAI API. e.g. http://127.0.0.1:7890
HTTPS_PROXY=
# Inject analytics or other scripts before </head> of the page
HEAD_SCRIPTS=
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create and publish a Docker image

on:
push:
branches: ['main']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ pnpm-debug.log*

# Local
*.local

**/.DS_Store

# Editor directories and files
.idea
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A demo repo based on [OpenAI GPT-3.5 Turbo API](https://platform.openai.com/docs

1. Setup & Install dependencies

> First, you need [Node.js](https://nodejs.org/) (v18+) installed.
> First, you need [Node.js](https://nodejs.org/) installed.
```shell
npm i
Expand Down
22 changes: 20 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { defineConfig } from 'astro/config'
import vercel from '@astrojs/vercel/edge'
import unocss from 'unocss/astro'
import { presetUno } from 'unocss'
import presetAttributify from '@unocss/preset-attributify'
import presetTypography from '@unocss/preset-typography'
import solidJs from '@astrojs/solid-js'
import vercelDisableBlocks from './plugins/vercelDisableBlocks'

import node from '@astrojs/node'
import vercel from '@astrojs/vercel/edge'

const envAdapter = () => {
if (process.env.OUTPUT == 'vercel') {
return vercel()
} else {
return node({
mode: 'standalone'
})
}
}

// https://astro.build/config
export default defineConfig({
Expand All @@ -19,5 +32,10 @@ export default defineConfig({
solidJs()
],
output: 'server',
adapter: vercel()
adapter: envAdapter(),
vite: {
plugins: [
process.env.OUTPUT == 'vercel' && vercelDisableBlocks(),
]
},
});
8 changes: 8 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

FROM node:alpine
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY . /usr/src
RUN npm install
EXPOSE 3000
CMD npm run start -- --port 3000 --host 0.0.0.0
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"build:vercel": "OUTPUT=vercel astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/node": "^5.0.4",
"@astrojs/solid-js": "^2.0.2",
"@astrojs/vercel": "^3.1.3",
"@unocss/reset": "^0.50.1",
Expand All @@ -20,7 +22,8 @@
"markdown-it": "^13.0.1",
"markdown-it-highlightjs": "^4.0.1",
"markdown-it-katex": "^2.0.3",
"solid-js": "^1.6.11"
"solid-js": "^1.6.11",
"undici": "^5.20.0"
},
"devDependencies": {
"@types/markdown-it": "^12.2.3",
Expand Down
16 changes: 16 additions & 0 deletions plugins/vercelDisableBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function plugin() {
const transform = (code: string, id: string) => {
if (id.includes('pages/api/generate.ts')) {
return {
code: code.replace(/^.*?#vercel-disable-blocks([\s\S]+?)#vercel-end.*?$/gm, ''),
map: null
}
}
}

return {
name: 'vercel-disable-blocks',
enforce: 'pre',
transform,
}
}
Loading

0 comments on commit e374f14

Please sign in to comment.