From 32ebd594670ba0f3537ca85ff81aff01d07cd7cb Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 10 Dec 2022 10:26:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=20test=20pour=20production?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 12 ++++++++++++ Jenkins | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkins diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e1196a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:alpine + +#copy source +COPY . /app + +# Install deps +RUN cd /app && npm install + +# Build +RUN npm run build + +ENTRYPOINT [ "npm", "run", "start" ] \ No newline at end of file diff --git a/Jenkins b/Jenkins new file mode 100644 index 0000000..1ad0dfd --- /dev/null +++ b/Jenkins @@ -0,0 +1,41 @@ +rm -rf $WORKSPACE/my-nextjs-project +git clone git@gitlab.com:me/my-nextjs-project.git $WORKSPACE/my-nextjs-project + +cd $WORKSPACE/my-nextjs-project +git checkout master + +yarn install +yarn build + +mkdir my-nextjs-project + +mv public/ my-nextjs-project/ + +NEXT_BUILD_ID=$(cat build/BUILD_ID) +LAST_COMMIT=$(git rev-parse HEAD) + +# That's just for debugging purposes +echo "{git: ${LAST_COMMIT}, ci: ${BUILD_ID}, next: ${NEXT_BUILD_ID}}" > my-nextjs-project/CI + +# trim package.json and leave only things that you need in production +cat package.json | jq '. | {name: .name, private: true, version: .version, scripts: {start: .scripts.start}, dependencies: .dependencies}' > my-nextjs-project/package.json + +# I'm using next-compose-plugins, so here we need to dump config. If you have next.config.js as an object then just copy config file +NEXT_CONFIG=$(node -e 'var configFile = require("./next.config.js"); var config = configFile([], {}); delete config.webpack; console.log(JSON.stringify(config));') +echo "module.exports = ${NEXT_CONFIG}" > my-nextjs-project/next.config.js # result => {distDir: "build", poweredByHeader: false} + +mv build my-nextjs-project/ + +cd my-nextjs-project + +yarn install + +cd $WORKSPACE/my-nextjs-project + +# dump folder tree structure just for Jenkins console output logs +tree -h -L 1 build/ + +tar czf $WORKSPACE/my-nextjs-project.tar.gz my-nextjs-project +cd $WORKSPACE + +rm -rf $WORKSPACE/my-nextjs-project \ No newline at end of file