From 0e1c9cb58368e3fac4e5f2ed2d969ddc1b60de55 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Tue, 14 Jul 2020 10:57:34 +0100 Subject: [PATCH 1/5] Containerise socket server See https://github.com/excalidraw/excalidraw/issues/1772#issuecomment-652043326 --- Dockerfile | 14 ++++++++++++++ package.json | 5 ++++- scripts/postinstall.js | 9 +++++++++ tsconfig.json | 3 ++- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 scripts/postinstall.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eb8ecc9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:14-alpine + +WORKDIR /excalidraw-room + +COPY package.json yarn.lock ./ +COPY scripts ./scripts +RUN SKIP_YARN_POSTINSTALL=true yarn + +COPY tsconfig.json ./ +COPY src ./src +RUN yarn build + +EXPOSE 80 +CMD ["yarn", "start"] diff --git a/package.json b/package.json index 807d4a0..12292e4 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "tsc", "fix": "yarn prettier --write", "lint": "yarn prettier --list-different", - "postinstall": "npm run build", + "postinstall": "node scripts/postinstall.js", "prettier": "prettier \"**/*.{ts,md,json,yaml,yml}\"", "start": "node dist/index.js", "test": "yarn lint" @@ -40,6 +40,9 @@ "typescript": "3.9.5" }, "eslintConfig": { + "env": { + "es6": true + }, "extends": [ "prettier" ], diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 0000000..e14b318 --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,9 @@ +// There doesn't appear to be a way to skip `postinstall`, +// as doing `yarn --ignore-scripts` could prevent native packages from building: +// https://github.com/yarnpkg/yarn/issues/4100 + +const { execSync } = require("child_process"); + +if (process.env.SKIP_YARN_POSTINSTALL !== "true") { + execSync("yarnpkg build", { stdio: "inherit" }); +} diff --git a/tsconfig.json b/tsconfig.json index a239fb1..54b76ae 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,6 @@ "resolveJsonModule": true, "isolatedModules": true, "outDir": "dist" - } + }, + "include": ["src/**/*"] } From 1a38ad91666994733e35a7a687babbf97d013450 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Tue, 14 Jul 2020 22:03:25 +0100 Subject: [PATCH 2/5] Use Node 12 image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index eb8ecc9..2002154 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:14-alpine +FROM node:12-alpine WORKDIR /excalidraw-room From 425fb98d708e7b6a0127e6cf7cdc203211ad8dfd Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Tue, 14 Jul 2020 23:29:47 +0100 Subject: [PATCH 3/5] Expand comment about `postinstall` --- scripts/postinstall.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index e14b318..0ca5207 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -1,5 +1,12 @@ -// There doesn't appear to be a way to skip `postinstall`, -// as doing `yarn --ignore-scripts` could prevent native packages from building: +// This allows `postinstall` to be skipped via `SKIP_YARN_POSTINSTALL=true`. +// This is useful when building a Docker image because it lets you +// take advantage of cached Docker layers and run Yarn +// only if `package.json` or `yarn.lock` changed, +// and not every time source code is updated: +// https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ +// +// However, there doesn't appear to be a way to skip `postinstall`, +// and doing `yarn --ignore-scripts` could prevent native packages from building: // https://github.com/yarnpkg/yarn/issues/4100 const { execSync } = require("child_process"); From 9d4a5b900c8b22b38def29a7e5af61a6c8cb38d9 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Thu, 16 Jul 2020 20:59:28 +0100 Subject: [PATCH 4/5] Add publish Docker GitHub action --- .github/workflows/publish-docker.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/publish-docker.yml diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 0000000..77f9bf0 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,20 @@ +name: Publish Docker + +on: + push: + branches: + - master + +jobs: + publish-docker: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: excalidraw/excalidraw-room + tag_with_ref: true + tag_with_sha: true From a859638b72d85f9fe71920899fa8ab433ac75e6b Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 17 Jul 2020 00:23:11 +0100 Subject: [PATCH 5/5] Remove postinstall --- Dockerfile | 3 +-- package.json | 4 ---- scripts/postinstall.js | 16 ---------------- tsconfig.json | 3 +-- 4 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 scripts/postinstall.js diff --git a/Dockerfile b/Dockerfile index 2002154..06c09cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,7 @@ FROM node:12-alpine WORKDIR /excalidraw-room COPY package.json yarn.lock ./ -COPY scripts ./scripts -RUN SKIP_YARN_POSTINSTALL=true yarn +RUN yarn COPY tsconfig.json ./ COPY src ./src diff --git a/package.json b/package.json index 12292e4..a6195e2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "build": "tsc", "fix": "yarn prettier --write", "lint": "yarn prettier --list-different", - "postinstall": "node scripts/postinstall.js", "prettier": "prettier \"**/*.{ts,md,json,yaml,yml}\"", "start": "node dist/index.js", "test": "yarn lint" @@ -40,9 +39,6 @@ "typescript": "3.9.5" }, "eslintConfig": { - "env": { - "es6": true - }, "extends": [ "prettier" ], diff --git a/scripts/postinstall.js b/scripts/postinstall.js deleted file mode 100644 index 0ca5207..0000000 --- a/scripts/postinstall.js +++ /dev/null @@ -1,16 +0,0 @@ -// This allows `postinstall` to be skipped via `SKIP_YARN_POSTINSTALL=true`. -// This is useful when building a Docker image because it lets you -// take advantage of cached Docker layers and run Yarn -// only if `package.json` or `yarn.lock` changed, -// and not every time source code is updated: -// https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ -// -// However, there doesn't appear to be a way to skip `postinstall`, -// and doing `yarn --ignore-scripts` could prevent native packages from building: -// https://github.com/yarnpkg/yarn/issues/4100 - -const { execSync } = require("child_process"); - -if (process.env.SKIP_YARN_POSTINSTALL !== "true") { - execSync("yarnpkg build", { stdio: "inherit" }); -} diff --git a/tsconfig.json b/tsconfig.json index 54b76ae..a239fb1 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,6 +12,5 @@ "resolveJsonModule": true, "isolatedModules": true, "outDir": "dist" - }, - "include": ["src/**/*"] + } }