Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
fix: yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
jreydman committed Oct 5, 2023
1 parent 22fba69 commit 3fdf692
Show file tree
Hide file tree
Showing 14 changed files with 12,530 additions and 23 deletions.
10 changes: 9 additions & 1 deletion server/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
/.husky
/docs
/files
/.yarn/unplugged


!yarn-offline-mirror/
!.yarn/plugins
!.yarn/releases
.yarn/cache
!package.json
!yarn.lock
!.yarnrc.yml
8 changes: 8 additions & 0 deletions server/.yarn/plugins/@yarnpkg/plugin-docker-build.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable */
module.exports = {
name: "@yarnpkg/plugin-docker-build",
factory: function (require) {
var plugin;(()=>{"use strict";var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{default:()=>u});const o=require("@yarnpkg/cli"),r=require("clipanion"),i=require("@yarnpkg/core"),a=require("@yarnpkg/plugin-patch"),n=require("@yarnpkg/fslib");const s=require("@yarnpkg/plugin-pack");async function c({workspace:t,destination:e,report:o}){await s.packUtils.prepareForPack(t,{report:o},async()=>{const r=await s.packUtils.genPackList(t),a=i.Report.progressViaCounter(r.length),c=o.reportProgress(a);try{for(const i of r){const r=n.ppath.join(t.cwd,i),s=n.ppath.join(e,t.relativeCwd,i);o.reportInfo(null,i),await n.xfs.copyPromise(s,r,{overwrite:!0}),a.tick()}}finally{c.stop()}})}function p(t,e){const o=(0,n.toFilename)(e);return n.ppath.isAbsolute(o)?n.ppath.relative(t,o):o}const l=/^builtin<([^>]+)>$/;var d=function(t,e,o,r){var i,a=arguments.length,n=a<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,o,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(n=(a<3?i(n):a>3?i(e,o,n):i(e,o))||n);return a>3&&n&&Object.defineProperty(e,o,n),n};class f extends o.BaseCommand{constructor(){super(...arguments),this.args=[]}async execute(){const t=await i.Configuration.find(this.context.cwd,this.context.plugins),{project:e}=await i.Project.find(t,this.context.cwd),o=e.getWorkspaceByIdent(i.structUtils.parseIdent(this.workspaceName)),r=function({project:t,workspaces:e,production:o=!1,scopes:r=(o?["dependencies"]:i.Manifest.hardDependencies)}){const a=new Set([...e]);for(const e of a)for(const o of r){const r=e.manifest.getForScope(o).values();for(const e of r){const o=t.tryWorkspaceByDescriptor(e);o&&a.add(o)}}for(const e of t.workspaces)a.has(e)?o&&e.manifest.devDependencies.clear():(e.manifest.dependencies.clear(),e.manifest.devDependencies.clear(),e.manifest.peerDependencies.clear());return a}({project:e,workspaces:[o],production:this.production}),s=await async function(t,e="Dockerfile"){const o=(0,n.toFilename)(e);if(n.ppath.isAbsolute(o))return o;const r=[n.ppath.join(t.cwd,o),n.ppath.join(t.project.cwd,o)];for(const t of r)if(await n.xfs.existsPromise(t))return t;throw new Error("Dockerfile is required")}(o,this.dockerFilePath),d=await i.Cache.find(t);return(await i.StreamReport.start({configuration:t,stdout:this.context.stdout,includeLogs:!this.context.quiet},async t=>{await t.startTimerPromise("Resolution Step",async()=>{await e.resolveEverything({report:t,cache:d})}),await t.startTimerPromise("Fetch Step",async()=>{await e.fetchEverything({report:t,cache:d})}),await n.xfs.mktempPromise(async o=>{const f=n.ppath.join(o,(0,n.toFilename)("manifests")),u=n.ppath.join(o,(0,n.toFilename)("packs"));await t.startTimerPromise("Copy files",async()=>{await async function({destination:t,project:e,report:o}){const r=e.configuration.get("rcFilename");o.reportInfo(null,r),await n.xfs.copyPromise(n.ppath.join(t,r),n.ppath.join(e.cwd,r),{overwrite:!0})}({destination:f,project:e,report:t}),await async function({destination:t,project:e,report:o}){const r=n.ppath.join((0,n.toFilename)(".yarn"),(0,n.toFilename)("plugins"));o.reportInfo(null,r),await n.xfs.copyPromise(n.ppath.join(t,r),n.ppath.join(e.cwd,r),{overwrite:!0})}({destination:f,project:e,report:t}),await async function({destination:t,project:e,report:o}){const r=e.configuration.get("yarnPath"),i=n.ppath.relative(e.cwd,r),a=n.ppath.join(t,i);o.reportInfo(null,i),await n.xfs.copyPromise(a,r,{overwrite:!0})}({destination:f,project:e,report:t}),await async function({destination:t,workspaces:e,report:o}){for(const r of e){const e=n.ppath.join(r.relativeCwd,i.Manifest.fileName),a=n.ppath.join(t,e),s={};r.manifest.exportTo(s),o.reportInfo(null,e),await n.xfs.mkdirpPromise(n.ppath.dirname(a)),await n.xfs.writeJsonPromise(a,s)}}({destination:f,workspaces:e.workspaces,report:t}),await async function({destination:t,report:e,project:o,parseDescriptor:r}){const a=new Set;for(const s of o.storedDescriptors.values()){const c=r(i.structUtils.isVirtualDescriptor(s)?i.structUtils.devirtualizeDescriptor(s):s);if(!c)continue;const{parentLocator:p,paths:d}=c;for(const r of d){if(l.test(r))continue;if(n.ppath.isAbsolute(r))continue;const i=o.getWorkspaceByLocator(p),s=n.ppath.join(i.relativeCwd,r);if(a.has(s))continue;a.add(s);const c=n.ppath.join(i.cwd,r),d=n.ppath.join(t,s);e.reportInfo(null,s),await n.xfs.mkdirpPromise(n.ppath.dirname(d)),await n.xfs.copyFilePromise(c,d)}}}({destination:f,report:t,project:e,parseDescriptor:t=>{if(t.range.startsWith("exec:")){const e=function(t){const{params:e,selector:o}=i.structUtils.parseRange(t),r=n.npath.toPortablePath(o);return{parentLocator:e&&"string"==typeof e.locator?i.structUtils.parseLocator(e.locator):null,path:r}}(t.range);if(!e||!e.parentLocator)return;return{parentLocator:e.parentLocator,paths:[e.path]}}if(t.range.startsWith("patch:")){const{parentLocator:e,patchPaths:o}=a.patchUtils.parseDescriptor(t);if(!e)return;return{parentLocator:e,paths:o}}}}),await async function({destination:t,project:e,cache:o,report:r}){for(const i of o.markedFiles){const o=n.ppath.relative(e.cwd,i);await n.xfs.existsPromise(i)&&(r.reportInfo(null,o),await n.xfs.copyPromise(n.ppath.join(t,o),i))}}({destination:f,project:e,cache:d,report:t}),await async function({destination:t,project:e,report:o}){const r=(0,n.toFilename)(e.configuration.get("lockfileFilename")),i=n.ppath.join(t,r);o.reportInfo(null,r),await n.xfs.mkdirpPromise(n.ppath.dirname(i)),await n.xfs.writeFilePromise(i,e.generateLockfile())}({destination:f,project:e,report:t}),this.copyFiles&&this.copyFiles.length&&await async function({destination:t,files:e,dockerFilePath:o,report:r}){const i=n.ppath.dirname(o);for(const o of e){const e=p(i,o),a=n.ppath.join(i,e),s=n.ppath.join(t,e);r.reportInfo(null,e),await n.xfs.copyPromise(s,a)}}({destination:f,files:this.copyFiles,dockerFilePath:s,report:t})});for(const e of r){const o=e.manifest.name?i.structUtils.stringifyIdent(e.manifest.name):"";await t.startTimerPromise("Pack workspace "+o,async()=>{await c({workspace:e,report:t,destination:u})})}const h=this.buildKit?["buildx","build"]:["build"];await i.execUtils.pipevp("docker",[...h,...this.args,"-f",s,"."],{cwd:o,strict:!0,stdin:this.context.stdin,stdout:this.context.stdout,stderr:this.context.stderr})})})).exitCode()}}f.usage=r.Command.Usage({category:"Docker-related commands",description:"Build a Docker image for a workspace",details:'\n This command will build a efficient Docker image which only contains necessary dependencies for the specified workspace.\n\n You have to create a Dockerfile in your workspace or your project. You can also specify the path to Dockerfile using the "-f, --file" option.\n\n Additional arguments can be passed to "docker build" directly, please check the Docker docs for more info: https://docs.docker.com/engine/reference/commandline/build/\n\n You can copy additional files or folders to a Docker image using the "--copy" option. This is useful for secret keys or configuration files. The files will be copied to "manifests" folder. The path can be either a path relative to the Dockerfile or an absolute path.\n ',examples:[["Build a Docker image for a workspace","yarn docker build @foo/bar"],["Pass additional arguments to docker build command","yarn docker build @foo/bar -t image-tag"],["Copy additional files to a Docker image","yarn docker build --copy secret.key --copy config.json @foo/bar"],["Install production dependencies only","yarn docker build --production @foo/bar"],["Build a Docker image using BuildKit","yarn docker build --buildkit @foo/bar"]]}),d([r.Command.String()],f.prototype,"workspaceName",void 0),d([r.Command.Proxy()],f.prototype,"args",void 0),d([r.Command.String("-f,--file")],f.prototype,"dockerFilePath",void 0),d([r.Command.Array("--copy")],f.prototype,"copyFiles",void 0),d([r.Command.Boolean("--production")],f.prototype,"production",void 0),d([r.Command.Boolean("--buildkit")],f.prototype,"buildKit",void 0),d([r.Command.Path("docker","build")],f.prototype,"execute",null);const u={commands:[f]};plugin=e})();
return plugin;
}
};
874 changes: 874 additions & 0 deletions server/.yarn/releases/yarn-3.6.4.cjs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion server/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
nodeLinker: node-modules

#yarnPath: .yarn/releases/yarn-3.6.3.cjs
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-docker-build.cjs
spec: "https://github.com/Dcard/yarn-plugins/releases/latest/download/plugin-docker-build.js"

yarnPath: .yarn/releases/yarn-3.6.4.cjs
2 changes: 1 addition & 1 deletion server/Docker/app.e2e.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG WORKDIR_FLOW
ARG COMPOSE_PROJECT_NAME
WORKDIR ${WORKDIR_FLOW}

COPY --from=cache /node_modules ./node_modules
COPY --from=cache /tmp/node_modules ./node_modules
COPY . .

RUN if [ ! -f .env ]; then cp ./env-example .env; fi
Expand Down
2 changes: 1 addition & 1 deletion server/Docker/app.prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM node:18 as build
ARG WORKDIR_FLOW
WORKDIR ${WORKDIR_FLOW}

COPY --from=cache /node_modules ./node_modules
COPY --from=cache /tmp/node_modules ./node_modules
COPY . .

RUN if [ ! -f .env ]; then cp ./env-example .env; fi
Expand Down
10 changes: 6 additions & 4 deletions server/Docker/cache.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
FROM node:18 as build

WORKDIR /tmp
MAINTAINER Pikj [Jreydman] Reyderman <[email protected]>

COPY ./package*.json ./
COPY ["package*.json", "yarn.lock", ".yarnrc.yml", "./"]
COPY .yarn ./.yarn

RUN yarn install
RUN yarn install --immutable

FROM alpine as release
WORKDIR /tmp

COPY --from=build /node_modules ./node_modules
COPY --from=build /tmp/node_modules ./node_modules



Expand Down
2 changes: 1 addition & 1 deletion server/Docker/db-prepare.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ARG WORKDIR_FLOW
WORKDIR ${WORKDIR_FLOW}
ARG APP_PORT

COPY --from=cache /node_modules ./node_modules
COPY --from=cache /tmp/node_modules ./node_modules

COPY ./package*.json .
COPY ./tsconfig*.json .
Expand Down
15 changes: 7 additions & 8 deletions server/Docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ services:
- virtual-ci
- local-ci
container_name: ${COMPOSE_PROJECT_NAME}-db-prepare
restart: unless-stopped
entrypoint: [ "/opt/startup.sh", "db-prepare" ]
<<: *common-config
build:
Expand Down Expand Up @@ -159,10 +158,10 @@ services:
- DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres
- MAIL_HOST=${COMPOSE_PROJECT_NAME}-maildev

volumes:
db-data:
driver: local
driver_opts:
type: none
o: bind
device: ${DATABASE_PATH_LOCAL}/data
#volumes:
# db-data:
# driver: local
# driver_opts:
# type: none
# o: bind
# device: ${DATABASE_PATH_LOCAL}/data
167 changes: 167 additions & 0 deletions server/Docker/docker-compose.yaml''
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
version: '3.9'

# profiles:
# - virtual-development
# - local-development
# - virtual-production
# - local-production
# - virtual-ci
# - local-ci

x-common-context: &common-context
context: ../

x-common-args: &common-args
args:
- WORKDIR_FLOW=$SERVER_PATH_CONTAINER
- APP_PORT=$APP_PORT
- COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME

x-common-config: &common-config
env_file:
- ../.env

x-common-healthcheck: &common-healthcheck
interval: 10s
timeout: 5s
retries: 5
start_period: 10s

x-common-api: &common-api
container_name: ${COMPOSE_PROJECT_NAME}-api
<<: *common-config
restart: unless-stopped
expose:
- ${APP_PORT}
ports:
- ${APP_PORT}:${APP_PORT}
depends_on:
db-prepare:
condition: service_completed_successfully
postgres:
condition: service_healthy
maildev:
condition: service_healthy


services:

postgres: #service
profiles:
- virtual-development
- local-development
- virtual-production
- local-production
- virtual-ci
- local-ci
container_name: ${COMPOSE_PROJECT_NAME}-postgres
image: postgres:16.0-alpine
<<: *common-config
expose:
- ${DATABASE_PORT}
restart: unless-stopped
environment:
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
healthcheck:
<<: *common-healthcheck
test: [ "CMD-SHELL", "pg_isready -d ${DATABASE_NAME} -U ${DATABASE_USERNAME}" ]
# <Virtual stage># <Virtual stage> ports: #toggle
# <Virtual stage># <Virtual stage> - ${DATABASE_PORT}:${DATABASE_PORT} #toggle
#endservice

maildev: #service
container_name: ${COMPOSE_PROJECT_NAME}-maildev
profiles:
- virtual-development
- local-development
- virtual-production
- local-production
- virtual-ci
- local-ci
restart: unless-stopped
build:
<<: *common-context
dockerfile: ${DOCKER_PATH_LOCAL}/maildev.Dockerfile
healthcheck:
<<: *common-healthcheck
test: [ "CMD-SHELL", "wget -O - http://localhost:${MAIL_CLIENT_PORT}/healthz || exit 1" ]
expose:
- ${MAIL_CLIENT_PORT}
- ${MAIL_PORT}
ports:
# <Virtual stage># <Virtual stage> - ${MAIL_PORT}:${MAIL_PORT} #toggle
- ${MAIL_CLIENT_PORT}:${MAIL_CLIENT_PORT}
#endservice

db-prepare:
profiles:
- virtual-development
- local-development
- virtual-production
- local-production
- virtual-ci
- local-ci
container_name: ${COMPOSE_PROJECT_NAME}-db-prepare
entrypoint: [ "/opt/startup.sh", "db-prepare" ]
<<: *common-config
build:
<<: [*common-context, *common-args]
dockerfile: ${DOCKER_PATH_LOCAL}/db-prepare.Dockerfile
environment:
- NODE_ENV=development
- DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres
depends_on:
postgres:
condition: service_healthy

api-development:
profiles:
- virtual-development
<<: *common-api
image: node:18-alpine
working_dir: ${SERVER_PATH_CONTAINER}
command: [ "yarn", "start:development" ]
volumes:
- ../:${SERVER_PATH_CONTAINER}
environment:
- NODE_ENV=development
- DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres
- MAIL_HOST=${COMPOSE_PROJECT_NAME}-maildev

api-production:
profiles:
- virtual-production
<<: [*common-api, *common-config]
restart: on-failure
command: ["/opt/startup.sh", "production"]
build:
<<: [*common-context, *common-args]
dockerfile: ${DOCKER_PATH_LOCAL}/app.prod.Dockerfile
environment:
- NODE_ENV=production
- DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres
- MAIL_HOST=${COMPOSE_PROJECT_NAME}-maildev

api-ci:
profiles:
- virtual-ci
<<: [ *common-api, *common-config ]
restart: on-failure
command: [ "/opt/startup.sh", "ci" ]
build:
<<: [ *common-context, *common-args ]
dockerfile: ${DOCKER_PATH_LOCAL}/app.e2e.Dockerfile
environment:
- NODE_ENV=production
- DATABASE_HOST=${COMPOSE_PROJECT_NAME}-postgres
- MAIL_HOST=${COMPOSE_PROJECT_NAME}-maildev

#volumes:
# db-data:
# driver: local
# driver_opts:
# type: none
# o: bind
# device: ${DATABASE_PATH_LOCAL}/data
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "npx env-cmd -- jest --config ./test/jest-e2e.json",
"prepare": "is-ci || cd .. && husky install ./server/.husky"
"prepare": "is-ci || cd .. && husky install ./.husky"
},
"dependencies": {
"@aws-sdk/client-s3": "3.414.0",
Expand Down Expand Up @@ -87,7 +87,7 @@
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-prettier": "5.0.0",
"husky": "8.0.3",
"husky": "latest",
"hygen": "6.2.11",
"is-ci": "3.0.1",
"jest": "29.7.0",
Expand Down
13 changes: 10 additions & 3 deletions server/sh-scripts/compose.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash
set -e

# Проверяем, является ли версия BSD
if strings "$(which sed)" | grep -qi "BSD"; then
sed_command="sed -i ''"
else
sed_command="sed -i"
fi

if [ -f /.dockerenv ]; then
PARENT_DIR=$SERVER_PATH_CONTAINER
else
Expand Down Expand Up @@ -59,16 +66,16 @@ sleep 3
reverse_stage_toggle() {
if [ "$1" = "local" ]; then
echo "Info! Setup docker-compose <Local>"
sed -i -e '/postgres: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#toggle/\1#toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#toggle/\1#toggle/;}' "$PARENT_DIR"/"$DOCKER_PATH_LOCAL"/docker-compose.yaml
$sed_command -e '/postgres: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#toggle/\1#toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/# <Virtual stage>\(.*\)#toggle/\1#toggle/;}' "$PARENT_DIR"/"$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Finish edit docker-compose"

fi
if [ "$1" = "virtual" ]; then
echo "Info! Setup docker-compose <Virtual>"
sed -i -e '/postgres: #service/,/#endservice/ {;s/\(.*\)#toggle/# <Virtual stage>\1#toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/\(.*\)#toggle/# <Virtual stage>\1#toggle/;}' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
$sed_command -e '/postgres: #service/,/#endservice/ {;s/\(.*\)#toggle/# <Virtual stage>\1#toggle/;}' -e '/maildev: #service/,/#endservice/ {;s/\(.*\)#toggle/# <Virtual stage>\1#toggle/;}' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
echo "Info! Finish edit docker-compose"
fi
sed -i -e 's/# <Virtual stage># <Virtual stage>/# <Virtual stage>/' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
$sed_command -e 's/# <Virtual stage># <Virtual stage>/# <Virtual stage>/' "$PARENT_DIR/$DOCKER_PATH_LOCAL"/docker-compose.yaml
}

case $stage in
Expand Down
2 changes: 1 addition & 1 deletion server/sh-scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ if [ "$1" == "db-prepare" ] ; then
npx ts-node -r tsconfig-paths/register src/libs/database/seeds/run-seed.ts
fi

return 0
echo false
Loading

0 comments on commit 3fdf692

Please sign in to comment.