Skip to content

Commit

Permalink
It's working!
Browse files Browse the repository at this point in the history
  • Loading branch information
Yshayy committed Jul 27, 2023
1 parent 35e2dfa commit 648d409
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
.git
.devcontainer
node_modules
**/node_modules
packages/*/dist
/tunnel-server
/site
Dockerfile*
tsconfig.tsbuildinfo
packages/*/tsconfig.tsbuildinfo
dist/**
out/**
preevy-bin
.dockerignore
33 changes: 25 additions & 8 deletions Dockerfile.cli
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
FROM node:18-bullseye as builder
FROM node:18-bullseye as base
FROM base as deps-files
WORKDIR /app
ADD yarn.lock package.json .
COPY packages packages
RUN find . -type f -not -iname "yarn.lock" -not -iname "package.json" -delete && find . -type l -delete && find . -type d -empty -delete

FROM alpine as ldid
RUN wget -q https://github.com/ProcursusTeam/ldid/releases/download/v2.1.5-procursus7/ldid_linux_aarch64 -O /usr/bin/ldid
RUN chmod +x /usr/bin/ldid

FROM base as builder
WORKDIR /app
COPY --link . /app/
COPY --from=deps-files /app /app
RUN --mount=type=cache,id=livecycle/preevy-cli/yarn-cache,target=/yarn/cache \
yarn --cache-folder=/yarn/cache

RUN yarn clean && yarn build
COPY --link . .
RUN yarn build

FROM builder as pkg
ARG CLI_TARGET=macos-arm64
WORKDIR /app/packages/cli
ENV PKG_CACHE_PATH=/pkg/cache
COPY --from=ldid --link /usr/bin/ldid /usr/bin/ldid
RUN --mount=type=cache,id=livecycle/preevy-cli/pkg-cache,target=/pkg/cache \
yarn pkg --public --public-packages tslib --options max_old_space_size=4096 -t node18-alpine-arm64 .
yarn pkg --no-dict --public --public-packages tslib --options max_old_space_size=4096 -t node18-${CLI_TARGET} .

FROM scratch as cli
ARG CLI_TARGET=macos-arm64
COPY --link --from=pkg /app/packages/cli/preevy /preevy
# use docker buildx build -f Dockerfile.cli --target=cli . --output=type=local,dest=./dist

# FROM docker:24-cli
# COPY --from=pkg /app/packages/cli/preevy /usr/bin/
# CMD [ "preevy" ]
FROM docker:24-cli as release
COPY --from=pkg /app/packages/cli/preevy /usr/bin/
CMD [ "preevy" ]
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"topicSeparator": " "
},
"pkg": {
"assets": ["../*/static/**/*", "../compose-tunnel-agent/out/**/*", "../compose-tunnel-agent/package.json"]
"assets": ["../*/static/**/*", "../compose-tunnel-agent/out/**/*", "../compose-tunnel-agent/package.json", "../compose-tunnel-agent/Dockerfile", "../compose-tunnel-agent/.dockerignore" ],
"scripts": ["dist/commands/**/*.js", "dist/hooks/**/*.js"]
},
"scripts": {
"build": "yarn clean && tsc -b",
Expand Down
54 changes: 39 additions & 15 deletions packages/core/src/compose-tunnel-agent-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from 'path'
import fetch from 'node-fetch'
import retry from 'p-retry'
import { mapValues } from 'lodash'
import { mapValues, memoize } from 'lodash'
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, statSync } from 'fs'
import { tmpdir } from 'os'
import { ComposeModel, ComposeService } from './compose/model'
import { TunnelOpts } from './ssh/url'
import { Tunnel } from './tunneling'
Expand All @@ -10,21 +12,43 @@ import { withBasicAuthCredentials } from './url'
export const COMPOSE_TUNNEL_AGENT_SERVICE_NAME = 'preevy_proxy'
export const COMPOSE_TUNNEL_AGENT_SERVICE_PORT = 3000
const COMPOSE_TUNNEL_AGENT_DIR = path.join(__dirname, '../../compose-tunnel-agent')
declare let process : {
pkg?: {}
}

const baseDockerProxyService: ComposeService = {
build: {
context: COMPOSE_TUNNEL_AGENT_DIR,
},
labels: {
'preevy.access': 'private',
},
function extractComposeTunnelAgentDir() {
// can't use fs.cpSync because it's not patched by pkg (https://github.com/vercel/pkg/blob/bb042694e4289a1cbc530d2938babe35ccc84a93/prelude/bootstrap.js#L600)
const copyDirRecursive = (sourceDir: string, targetDir:string) => {
if (!existsSync(targetDir)) {
mkdirSync(targetDir)
}
const files = readdirSync(sourceDir)
for (const file of files) {
const sourcePath = path.join(sourceDir, file)
const targetPath = path.join(targetDir, file)
const stat = statSync(sourcePath)
if (stat.isDirectory()) {
copyDirRecursive(sourcePath, targetPath)
} else {
copyFileSync(sourcePath, targetPath)
}
}
}
const dest = mkdtempSync(path.join(tmpdir(), 'compose-tunnel-agent'))
copyDirRecursive(COMPOSE_TUNNEL_AGENT_DIR, dest)
return dest
}

export const minimalModelWithDockerProxyService = (name: string): ComposeModel => ({
name,
services: {
[COMPOSE_TUNNEL_AGENT_SERVICE_NAME]: baseDockerProxyService,
},
const baseDockerProxyService = memoize(() => {
const contextDir = process?.pkg ? extractComposeTunnelAgentDir() : COMPOSE_TUNNEL_AGENT_DIR
return {
build: {
context: contextDir,
},
labels: {
'preevy.access': 'private',
},
} as ComposeService
})

export const addBaseComposeTunnelAgentService = (
Expand All @@ -33,7 +57,7 @@ export const addBaseComposeTunnelAgentService = (
...model,
services: {
...model.services,
[COMPOSE_TUNNEL_AGENT_SERVICE_NAME]: baseDockerProxyService,
[COMPOSE_TUNNEL_AGENT_SERVICE_NAME]: baseDockerProxyService(),
},
})

Expand All @@ -52,7 +76,7 @@ export const addComposeTunnelAgentService = (
services: {
...model.services,
[COMPOSE_TUNNEL_AGENT_SERVICE_NAME]: {
...baseDockerProxyService,
...baseDockerProxyService(),
restart: 'always',
networks: Object.keys(model.networks || {}),
ports: [
Expand Down
1 change: 0 additions & 1 deletion packages/core/static/compose-tunnel-agent

This file was deleted.

0 comments on commit 648d409

Please sign in to comment.