Skip to content
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
6 changes: 2 additions & 4 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,5 @@ jobs:
- uses: ./.github/actions/node-install
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: .
target: playground
- run: |
pnpm docker:build
22 changes: 0 additions & 22 deletions Dockerfile

This file was deleted.

8 changes: 0 additions & 8 deletions docker-compose.yml

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "monorepo-typescript",
"private": true,
"author": "Coldrun <info@coldrun.com>",
"homepage": "https://github.com/coldrun/monorepo-typescript",
"repository": "https://github.com/coldrun/monorepo-typescript",
"type": "module",
"packageManager": "pnpm@10.30.1",
"engineStrict": true,
Expand All @@ -13,7 +13,7 @@
"scripts": {
"dev": "pnpm -r --parallel run dev",
"build": "pnpm -r run build",
"build:docker": "pnpm -r --stream run build:docker",
"docker:build": "pnpm -r --stream run docker:build",
"clean": "rimraf --glob packages/*/dist apps/*/dist temp .eslintcache",
"clean:all": "pnpm clean && rimraf --glob node_modules packages/*/node_modules apps/*/node_modules",
"format": "prettier . --write --ignore-unknown",
Expand Down
39 changes: 39 additions & 0 deletions packages/playground/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM node:24-slim AS base

ARG ENV=prod

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/*
RUN corepack enable

FROM base AS build

WORKDIR /app

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc tsconfig.json ./
COPY packages/core packages/core
COPY packages/shared packages/shared
COPY packages/playground packages/playground

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
--mount=type=secret,id=npmrc,target=/root/.npmrc \
pnpm install --frozen-lockfile
RUN pnpm build

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
--mount=type=secret,id=npmrc,target=/root/.npmrc \
pnpm deploy --legacy --filter="@coldrun/monorepo-typescript-playground" --prod /app/deploy

FROM nginx:stable AS playground

COPY packages/playground/.docker/nginx.conf /etc/nginx/conf.d/default.conf
COPY packages/playground/.docker/expires.conf /etc/nginx/conf.d/expires.conf

COPY --from=build /app/deploy/dist /app
COPY --from=build /app/deploy/node_modules /app/node_modules

RUN ls -al /app
RUN ls -al /app/node_modules
#ENTRYPOINT ["node", "main.js"]
3 changes: 2 additions & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:docker": "node ../../scripts/docker build playground",
"docker:build": "node ../../scripts/docker.js build playground",
"docker:push": "node ../../scripts/docker.js push playground",
"preview": "vite preview"
},
"dependencies": {
Expand Down
55 changes: 30 additions & 25 deletions scripts/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ const packages = fs.readdirSync(packagesPath);

const {
docker: { registry },
homepage,
repository,
} = createRequire(`${rootPath}/`)('./package.json');
const { version } = createRequire(`${rootPath}/`)('./lerna.json');

const exec = (bin, args, opts = {}) =>
execa(bin, args, { stdio: 'inherit', cwd: rootPath, ...opts });

const imageInfo = (target, tag) => {
function imageInfo(target, { tag }) {
if (!packages.includes(target)) {
throw new Error(`Invalid target: '${target}'`);
}
const targetPath = `${packagesPath}/${target}`;
const targetPackage = createRequire(import.meta.url)(`${targetPath}/package.json`);
const name = targetPackage.name.replace('@', '');
const packageName = `${registry}/${name}`;
const currentImage = `${packageName}:v${version}`;
const tagImage = `${packageName}:${tag}`;
const name = targetPackage.name.split('/').pop();
const tagName = tag || 'latest';

return { packageName, currentImage, tagImage };
};
const imageName = `${registry}/${name}`;
const image = `${imageName}:${tagName}`;

return { imageName, image, targetPath };
}

yargs(hideBin(process.argv))
.command(
Expand All @@ -45,18 +45,18 @@ yargs(hideBin(process.argv))
},
async (args) => {
const { target, tag, verbose } = args;
const { currentImage, tagImage } = imageInfo(target, tag);
const { image, targetPath } = imageInfo(target, { tag });
const dockerArgs = [
'build',
'.',
'--target',
target,
'-f',
`${targetPath}/Dockerfile`,
'--label',
`org.opencontainers.image.source=${homepage}`,
'-t',
currentImage,
`org.opencontainers.image.source=${repository}`,
'-t',
tagImage,
image,
'--secret',
`id=npmrc,src=${process.env.HOME}/.npmrc`,
];
if (verbose) {
dockerArgs.push('--progress', 'plain');
Expand All @@ -69,19 +69,24 @@ yargs(hideBin(process.argv))
'push <target>',
'push docker image',
{
tag: { alias: 't', default: 'latest' },
verbose: { alias: 'v', type: 'boolean' },
},
async (args) => {
const { target, tag, verbose } = args;
const { packageName } = imageInfo(target, tag);
const dockerArgs = ['push', packageName, '-a'];
if (verbose) {
dockerArgs.push('--progress', 'plain');
}
console.log('Running docker:', dockerArgs.join(' '));
await exec('docker', dockerArgs);
const { target, verbose } = args;
const { image } = imageInfo(target, {});

const push = async (args) => {
if (verbose) {
args.push('--progress', 'plain');
}
console.log('Running docker:', args.join(' '));
await exec('docker', args);
};

const dockerArgs = ['push', image];
await push(dockerArgs);
},
)
.help()
.demandCommand()
.parse();