Skip to content

Docker UI build #45

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

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions ui/.ackrc → .ackrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--ignore-dir=coverage
--ignore-dir=dist
--ignore-dir=node_modules
--ignore-dir=static/ui
--ignore-dir=tmp
--ignore-dir=vendor
--ignore-file=ext:svg
Expand Down
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
FROM golang:1.22.0-alpine3.19 AS build
RUN apk add -U --no-cache make git npm
FROM node:18-alpine as build-ui
RUN apk add -U --no-cache make git
COPY ui /src
WORKDIR /src
RUN make

FROM golang:1.22.0-alpine3.19 AS build-go
RUN apk add -U --no-cache make git
COPY . /src/gptscript
COPY --from=build-ui /src/.output/public /src/gptscript/static/ui
WORKDIR /src/gptscript

RUN make all
RUN make build

FROM alpine AS release
COPY --from=build /src/gptscript/bin /usr/local/bin/
WORKDIR /src
COPY --from=build-go /src/gptscript/bin /usr/local/bin/
COPY --from=build-go /src/gptscript/examples /src/examples
ENTRYPOINT ["/usr/local/bin/gptscript"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ all: build-ui build

build-ui:
$(MAKE) -C ui
rm -rf static/ui
mkdir -p static/ui/_nuxt
touch static/ui/placeholder static/ui/_nuxt/_placeholder
cp -rp ui/.output/public/* static/ui/

build:
CGO_ENABLED=0 go build -o bin/gptscript -tags "${GO_TAGS}" -ldflags "-s -w" .
Expand Down
3 changes: 0 additions & 3 deletions ui/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
build: clean
npm install
npm run generate
rm -rf ../static/ui/_nuxt
cp -rp .output/public/* ../static/ui/
touch ../static/ui/_nuxt/_placeholder

clean:
npm run clean
4 changes: 3 additions & 1 deletion ui/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import pkg from './package.json'
dotenv.config()

const port = 9091
const isDev = process.env.NODE_ENV === 'development'
const api = process.env.NUXT_PUBLIC_API || (isDev ? 'http://localhost:9090/' : '/')

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
Expand Down Expand Up @@ -35,7 +37,7 @@ export default defineNuxtConfig({
nitro: { sourceMap: true },
runtimeConfig: {
public: {
api: (process.env.NUXT_PUBLIC_API || 'http://localhost:9090/').replace(/\/+$/,'')+'/',
api: api.replace(/\/+$/,'')+'/',
},
},
sourcemap: true,
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<img src="~/assets/logo.svg" width="300px" style="aspect-ratio: preserve;" class="inline m-5" align="center" />

<h2 class="mt-20"><i class="i-heroicons-arrow-long-left align-middle text-lg"/> Choose a script to get started.</h2>
<h2 class="mt-10"><i class="i-heroicons-arrow-long-left align-middle text-lg"/> Choose a script to get started.</h2>
</div>
</template>
4 changes: 2 additions & 2 deletions ui/stores/gpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useGpts = defineStore('gpts', {
}

const url = useRuntimeConfig().public.api + id
const data = reactive<Gpt>(await $fetch(url))
const data = reactive<Gpt>(await $fetch(url, {baseURL: '/'}))

this.list.push(data)
this.map[id] = data
Expand All @@ -27,7 +27,7 @@ export const useGpts = defineStore('gpts', {

async listAll() {
const url = useRuntimeConfig().public.api
const data = await $fetch(url, {headers: {'X-Requested-With': 'fetch'} }) as string[]
const data = await $fetch(url, {baseURL: '/', headers: {'X-Requested-With': 'fetch'} }) as string[]
return reactive(data)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/stores/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useRuns = defineStore('runs', {
url = addParam(url, 'tool', toolName)
}

const res = await $fetch(url, {method: 'POST', body: args}) as {id: string}
const res = await $fetch(url, {baseURL: '/', method: 'POST', body: args}) as {id: string}
const id = res.id

const obj: Run = reactive({
Expand Down
8 changes: 7 additions & 1 deletion ui/stores/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ interface SocketState {

export const useSocket = defineStore('socket', {
state: () => {
const url = useRuntimeConfig().public.api.replace(/^http/,'ws')
let url = useRuntimeConfig().public.api
if ( url.startsWith('/') ) {
url = `${window.location.origin}${url}`
}

url = url.replace(/^http/,'ws')

const sock = useWebSocket(url, {
immediate: false,
autoReconnect: true,
Expand Down