From fabed985812aeec987097a55e9aa11dd37087eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Djk=C3=A1=C5=A5o?= Date: Fri, 10 May 2024 20:05:49 +0200 Subject: [PATCH] almost got it working --- Dockerfile | 27 +++++++++++++++++++++++++++ Makefile.toml | 9 +++++++-- apply_patches.sh | 22 ---------------------- changes.sh | 32 ++++++++++++++++++++++++-------- changes/snippets/turbo_env.ts | 2 +- make_patches.sh | 30 ------------------------------ modify-turbo-json/src/main.rs | 5 +++++ 7 files changed, 64 insertions(+), 63 deletions(-) create mode 100644 Dockerfile delete mode 100755 apply_patches.sh delete mode 100755 make_patches.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a50ce11 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM node:18-alpine as base +RUN apk add --no-cache g++ make py3-pip libc6-compat +WORKDIR /app +COPY package*.json ./ + +FROM base as builder +WORKDIR /app +COPY . . +RUN npm i -g pnpm &&\ + pnpm i &&\ + pnpm run build + + +FROM base as production +WORKDIR /app + +ENV NODE_ENV=production +RUN addgroup -g 1001 -S nodejs &&\ + adduser -S nextjs -u 1001 +USER nextjs + +COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next +# COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/public ./public + +CMD npm start diff --git a/Makefile.toml b/Makefile.toml index 97412ae..51f4814 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,4 +1,8 @@ - +[tasks.apply-changes] +alias = "apply-changes" +script = ''' +./changes.sh +''' # Configures the default task to run [tasks.default] alias = "build-containers" @@ -17,7 +21,8 @@ docker tag $(docker image ls -q --filter=label=service=chef-simple-payment-gatew [tasks.build-containers] dependencies = [ "delete-images", - "build-sitemap-generator", + "apply-changes", + "build-", "build-simple-payment-gateway", ] diff --git a/apply_patches.sh b/apply_patches.sh deleted file mode 100755 index 8898381..0000000 --- a/apply_patches.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -CURR_PWD="$(pwd)" - -app_paths=( - "apps" - "saleor-app-abandoned-checkouts" - "saleor-app-payment-authorize.net" - "saleor-app-payment-klarna" - "saleor-app-payment-stripe" -) - -echo "creating patches for all repos" - -for i in ${app_paths[*]}; do - cd "./all_apps/$i" - echo $(pwd) - git apply "$CURR_PWD/patches/$i.patch" - # pnpm i - # pnpm i ioredis - cd "$CURR_PWD" -done diff --git a/changes.sh b/changes.sh index 8c175e9..d7cf0e4 100755 --- a/changes.sh +++ b/changes.sh @@ -1,7 +1,8 @@ #!/bin/bash -REDIS_APL_PATH="./changes/snippets/redis_apl.ts" CURR_PWD="$(pwd)" +REDIS_APL_PATH="$CURR_PWD/changes/snippets/redis_apl.ts" +DOCKERFILE_PATH="$CURR_PWD/Dockerfile" app_paths=( "apps/apps/cms-v2" @@ -42,22 +43,37 @@ redis_apl_target_paths=( ) echo "copying redis_apls..." - -# always copies next to saleor-app.ts, so let's add some files to that file too -find . -name "saleor-app.ts" -exec cargo run --package modify-saleor-app -- {} \; -echo "modified $i to use redis_apl" -find . -name "turbo.json" -exec cargo run --package modify-turbo-json -- {} \; -echo "modified $i to turbo.json" - for i in ${redis_apl_target_paths[*]}; do echo "copying redis_apl.ts to ./all_apps/$i" cp -f "$REDIS_APL_PATH" "./all_apps/$i" done +find ./all_apps/apps -name "saleor-app.ts" -exec cargo run --package modify-saleor-app -- {} \; +echo "pached all_apps/apps/**/saleor-app.ts" + +find ./all_apps/saleor-app-abandoned-checkouts -name "saleor-app.ts" -exec cargo run --package modify-saleor-app -- {} \; +echo "pached all_apps/saleor-app-abandoned-checkouts/**/saleor-app.ts" + +find ./all_apps/apps/apps -name "turbo.json" -exec cargo run --package modify-turbo-json -- {} \; +echo "pached all_apps/**/turbo.json" + +cd ./all_apps/ +for i in "saleor-app-payment-klarna" "saleor-app-payment-stripe" "saleor-app-payment-authorize.net"; do + cd "$i" + git apply "$CURR_PWD/patches/$i/env.mjs.patch" + git apply "$CURR_PWD/patches/$i/saleor-app.ts.patch" + git apply "$CURR_PWD/patches/$i/next.config.mjs.patch" + echo "patched $i" + cd .. +done + +cd "$CURR_PWD" + for i in ${app_paths[*]}; do cd "./all_apps/$i" echo $(pwd) pnpm i pnpm i ioredis + cp -f "$DOCKERFILE_PATH" . cd "$CURR_PWD" done diff --git a/changes/snippets/turbo_env.ts b/changes/snippets/turbo_env.ts index 3bcb9ed..8566764 100644 --- a/changes/snippets/turbo_env.ts +++ b/changes/snippets/turbo_env.ts @@ -1 +1 @@ - "REDIS_URL", + "REDIS_URL", diff --git a/make_patches.sh b/make_patches.sh deleted file mode 100755 index 678031f..0000000 --- a/make_patches.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -REDIS_APL_PATH="./changes/snippets/redis_apl.ts" -CURR_PWD="$(pwd)" - -app_paths=( - "apps" - "saleor-app-abandoned-checkouts" - "saleor-app-payment-authorize.net" - "saleor-app-payment-klarna" - "saleor-app-payment-stripe" -) - -echo "creating patches for all repos" - -# for i in ${redis_apl_target_paths[*]}; do -# echo "copying redis_apl.ts to ./all_apps/$i" -# cp -f "$REDIS_APL_PATH" "./all_apps/$i" -# # always copies next to saleor-app.ts, so let's add some files to that file too -# # find . -name "saleor-app.ts" -exec sed "/switch/ r $CURR_PWD/changes/case_redisapl.ts" {} \; -# done -# -for i in ${app_paths[*]}; do - cd "./all_apps/$i" - echo "creating patch for $(pwd)" - git diff >"$CURR_PWD/patches/$i.patch" - # pnpm i - # pnpm i ioredis - cd "$CURR_PWD" -done diff --git a/modify-turbo-json/src/main.rs b/modify-turbo-json/src/main.rs index 44bad13..79f8405 100644 --- a/modify-turbo-json/src/main.rs +++ b/modify-turbo-json/src/main.rs @@ -12,11 +12,16 @@ fn main() -> Result<(), io::Error> { let mut file = read_to_string(&args[1])?; let mut output = "".to_owned(); + let mut is_done = false; for line in file.as_mut().lines() { output.push_str(&(line.to_owned() + "\n")); + if is_done { + continue; + }; if line.contains(r#""env":"#) { let case = fs::read_to_string("./changes/snippets/turbo_env.ts")?; output.push_str(&case); + is_done = true; } } fs::write(&args[1], output)?;