From 5ea047d0f012a5837b68fbc32cd841da7ad197d6 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 24 Jun 2023 14:58:09 +0900 Subject: [PATCH 01/34] Enable dockerfile plugin in dprint --- dprint.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dprint.json b/dprint.json index cf5bc19d..af7e1382 100644 --- a/dprint.json +++ b/dprint.json @@ -9,17 +9,20 @@ }, "json": {}, "markdown": {}, + "dockerfile": { + }, "prettier": { "printWidth": 120, "singleQuote": true }, - "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,yml,toml}"], + "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,dockerfile,yml}", "Dockerfile"], "excludes": ["**/node_modules", "**/*-lock.json", "lib/**", "dist/**"], "plugins": [ "https://plugins.dprint.dev/typescript-0.85.0.wasm", "https://plugins.dprint.dev/json-0.17.4.wasm", "https://plugins.dprint.dev/markdown-0.15.3.wasm", "https://plugins.dprint.dev/toml-0.5.4.wasm", + "https://plugins.dprint.dev/dockerfile-0.3.0.wasm", "https://plugins.dprint.dev/prettier-0.24.0.json@9a57d0d8e440ad90d07a503166af47e7a6a886abd46767933f9c279f72468596" ] } From 358d774b613697e7d7a533667968451cc3fc8a4a Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 24 Jun 2023 16:58:09 +0900 Subject: [PATCH 02/34] WIP --- CONTRIBUTING.md | 29 +++++++++++++++++++++++++++-- Dockerfile | 6 ++++++ Makefile.toml | 7 +++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3af83382..dad403ba 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,8 @@ ## Setup +### Nix + 1. Install [Nix](https://nixos.org/) package manager 2. Run `nix-shell` 3. You can use development tasks @@ -9,10 +11,33 @@ ```console > nix-shell (prepared bash) +``` + +### Docker + +You can use Docker to skip installing Nix on your local machine. + +```console +> docker run --interactive --tty --rm --volume "$(pwd):$(pwd)" --workdir "$(pwd)" nixos/nix nix-shell +[nix-shell:/home/YOUR_NAME/wait-other-jobs]# +``` + +Or use cached builds. +```console +> docker pull kachick/wait-other-jobs +> docker run --interactive --tty --rm --volume "$(pwd):$(pwd)" --workdir "$(pwd)" kachick/wait-other-jobs nix-shell +[nix-shell:/home/YOUR_NAME/wait-other-jobs]# +``` + +### Tasks + +```console > makers help -Tools ----------- +> Tools + +--- + check - ... help - ... diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a91f4ed0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM nixos/nix + +WORKDIR /wait-other-jobs/build +COPY default.nix default.nix +RUN nix-channel --update +RUN nix-build diff --git a/Makefile.toml b/Makefile.toml index a10f957b..9dcb03a9 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -70,6 +70,13 @@ category = "Tools" description = 'Parallel runner for all tests and linters' run_task = { name = ["typecheck", "test-ts", "test-js", "lint-check"], parallel = true } +[tasks.build-docker] +category = "Tools" +description = 'Build docker image for developt' +script = [ + "docker build . --tag wait-other-jobs:latest --file Dockerfile", +] + [tasks.help] category = "Tools" description = 'Might help you - (This one)' From 24e80a9b21a4e2fd413ba5c0a52f54464c9ed50e Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 24 Jun 2023 17:28:41 +0900 Subject: [PATCH 03/34] Devcontainer --- Dockerfile => .devcontainer/Dockerfile | 0 .devcontainer/devcontainer.json | 40 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) rename Dockerfile => .devcontainer/Dockerfile (100%) create mode 100644 .devcontainer/devcontainer.json diff --git a/Dockerfile b/.devcontainer/Dockerfile similarity index 100% rename from Dockerfile rename to .devcontainer/Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..f23f2c0a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +{ + "build": { + "dockerfile": "Dockerfile" + }, + "postCreateCommand": "makers setup", + "customizations": { + "vscode": { + "settings": { + "typescript.tsdk": "node_modules/typescript/lib", + "editor.defaultFormatter": "dprint.dprint", + "editor.formatOnSave": true, + "[nix]": { + "editor.defaultFormatter": "jnoortheen.nix-ide" + }, + "json.schemas": [ + { + "fileMatch": [ + "dprint.json" + ], + "url": "https://docs.renovatebot.com/renovate-schema.json" + } + ], + "cSpell.words": [ + "deno", + "dprint", + "OIDC", + "rmrf" + ] + }, + "extensions": [ + "dbaeumer.vscode-eslint", + "redhat.vscode-yaml", + "editorconfig.editorconfig", + "dprint.dprint", + "jnoortheen.nix-ide", + "tamasfe.even-better-toml" + ] + } + } +} From 86f1550be2dbaa4cf20290ff8c72f0f741e0d0c0 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sun, 25 Jun 2023 04:52:59 +0900 Subject: [PATCH 04/34] Super hard! --- .devcontainer/Dockerfile | 36 ++++++++++++++++++++++++++++----- .devcontainer/bootstrap.bash | 2 ++ .devcontainer/devcontainer.json | 5 +++-- .envrc | 1 + default.nix | 1 + dprint.json | 2 +- 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100755 .devcontainer/bootstrap.bash create mode 100644 .envrc diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a91f4ed0..30679c20 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,6 +1,32 @@ -FROM nixos/nix +# Do not use `FROM nixos/nix`. It cannot use `groupadd` even not the NixOS +# See https://stackoverflow.com/questions/75653182/why-do-some-official-nix-docker-containers-not-have-the-nixos-rebuild-command +FROM mcr.microsoft.com/devcontainers/base:ubuntu -WORKDIR /wait-other-jobs/build -COPY default.nix default.nix -RUN nix-channel --update -RUN nix-build +# Above microsoft image includes this user +USER vscode + +WORKDIR /home/vscode/sandbox + +# The install scripts will be syntax error if it will be eval with dash +SHELL ["/bin/bash", "-c"] + +# daemon mode required systemd, docker disables it +# As I understand the definition https://hub.docker.com/r/nixos/nix/dockerfile at Nix 2.17, it looks like a single user installation(no-daemon) +# See https://github.com/NixOS/nix/blob/fd4f03b8fdcb0f33552730c786139019e29f5dbe/scripts/install-nix-from-closure.sh#L129-L139 +RUN bash <(curl -L https://nixos.org/nix/install) --no-daemon --yes + +ENV PATH /home/vscode/.nix-profile/bin:$PATH + +# Make sure the building phase done. To cache. `nix-build --no-out-link` does similar, but it skips bash. +# NOTE: This does not mean the entry point is in nix-shell. +COPY ["../default.nix", "../Makefile.toml", "../package.json", "../package-lock.json", "./"] + +# Do no include like `npm install` here. Cuurently I don't cache it in container +RUN nix-channel --update && nix-shell --run 'echo "Welcome to this project :)"' +COPY ["../.envrc", "./"] +RUN nix-shell --run 'direnv allow' +COPY ["./.devcontainer/bootstrap.bash", "./"] +RUN ./bootstrap.bash + +# This can be skipped if you specify `docker run -it wait-other-jobs:ubuntu bash`. Also skipped in devcontainer, Use postCreateCommand instead. +# CMD nix-shell --command zsh diff --git a/.devcontainer/bootstrap.bash b/.devcontainer/bootstrap.bash new file mode 100755 index 00000000..61fed050 --- /dev/null +++ b/.devcontainer/bootstrap.bash @@ -0,0 +1,2 @@ +echo 'eval "$(nix-shell --run '"'"'direnv hook bash'"'"')"' >> ~/.bashrc +echo 'eval "$(nix-shell --run '"'"'direnv hook zsh'"'"')"' >> ~/.zshrc diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f23f2c0a..567df8c8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,8 +1,9 @@ { "build": { - "dockerfile": "Dockerfile" + "dockerfile": "Dockerfile", + "context": ".." }, - "postCreateCommand": "makers setup", + "remoteUser": "vscode", "customizations": { "vscode": { "settings": { diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..4a4726a5 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_nix diff --git a/default.nix b/default.nix index 9d49e003..8b9ba139 100644 --- a/default.nix +++ b/default.nix @@ -2,6 +2,7 @@ pkgs.mkShell { buildInputs = [ + pkgs.direnv pkgs.nodejs-16_x pkgs.dprint pkgs.cargo-make diff --git a/dprint.json b/dprint.json index af7e1382..038100c8 100644 --- a/dprint.json +++ b/dprint.json @@ -15,7 +15,7 @@ "printWidth": 120, "singleQuote": true }, - "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,dockerfile,yml}", "Dockerfile"], + "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,dockerfile,yml}", "**/Dockerfile"], "excludes": ["**/node_modules", "**/*-lock.json", "lib/**", "dist/**"], "plugins": [ "https://plugins.dprint.dev/typescript-0.85.0.wasm", From c4eff5d6e3048954a11d75df7cd8a6f4db118581 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Mon, 26 Jun 2023 18:42:16 +0900 Subject: [PATCH 05/34] Drop dprint-plugin-dockerfile to avoid the incorrect alerts https://github.com/dprint/dprint-plugin-dockerfile/issues/7 --- dprint.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/dprint.json b/dprint.json index 3b9a583a..fd4643ff 100644 --- a/dprint.json +++ b/dprint.json @@ -9,8 +9,6 @@ }, "json": {}, "markdown": {}, - "dockerfile": { - }, "prettier": { "printWidth": 120, "singleQuote": true @@ -22,7 +20,6 @@ "https://plugins.dprint.dev/json-0.17.4.wasm", "https://plugins.dprint.dev/markdown-0.15.3.wasm", "https://plugins.dprint.dev/toml-0.5.4.wasm", - "https://plugins.dprint.dev/dockerfile-0.3.0.wasm", "https://plugins.dprint.dev/prettier-0.26.1.json@fdbe31f6aecd24f9d6b924214710a6766050d03146163b4e241e6056b2462f2e" ] } From 4998b5715841ac5a213e2e23db5870df3139613f Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Mon, 26 Jun 2023 18:39:48 +0900 Subject: [PATCH 06/34] Integrate hadolint --- .devcontainer/Dockerfile | 3 +++ .devcontainer/devcontainer.json | 3 ++- .github/workflows/hadolint.yml | 23 +++++++++++++++++++++++ .vscode/extensions.json | 3 ++- Makefile.toml | 6 ++++-- default.nix | 1 + 6 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/hadolint.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 30679c20..9250a1d5 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,6 +10,9 @@ WORKDIR /home/vscode/sandbox # The install scripts will be syntax error if it will be eval with dash SHELL ["/bin/bash", "-c"] +# TODO: Remove this line. After checked the hadolint correctly alerts +RUN cd /tmp + # daemon mode required systemd, docker disables it # As I understand the definition https://hub.docker.com/r/nixos/nix/dockerfile at Nix 2.17, it looks like a single user installation(no-daemon) # See https://github.com/NixOS/nix/blob/fd4f03b8fdcb0f33552730c786139019e29f5dbe/scripts/install-nix-from-closure.sh#L129-L139 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 567df8c8..91704330 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -34,7 +34,8 @@ "editorconfig.editorconfig", "dprint.dprint", "jnoortheen.nix-ide", - "tamasfe.even-better-toml" + "tamasfe.even-better-toml", + "exiasr.hadolint" ] } } diff --git a/.github/workflows/hadolint.yml b/.github/workflows/hadolint.yml new file mode 100644 index 00000000..0aae78c7 --- /dev/null +++ b/.github/workflows/hadolint.yml @@ -0,0 +1,23 @@ +name: hadolint +on: + push: + branches: [main] + paths: + - '**Dockerfile' + - '**.dockerfile' + - '.github/workflows/hadolint.yml' + pull_request: + paths: + - '**Dockerfile' + - '**.dockerfile' + - '.github/workflows/hadolint.yml' + +jobs: + lint: + timeout-minutes: 15 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: hadolint/hadolint-action@v3.1.0 + with: + recursive: 'true' diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 06b6b596..a800e7c0 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,6 +5,7 @@ "editorconfig.editorconfig", "dprint.dprint", "jnoortheen.nix-ide", - "tamasfe.even-better-toml" + "tamasfe.even-better-toml", + "exiasr.hadolint" ] } diff --git a/Makefile.toml b/Makefile.toml index 86ca75bc..42cc823d 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -41,6 +41,7 @@ dependencies = [ "format-check", ] script = [ + "hadolint .devcontainer/Dockerfile", "npm run lint:check", ] @@ -72,9 +73,9 @@ run_task = { name = ["typecheck", "test-ts", "test-js", "lint-check"], parallel [tasks.build-docker] category = "Tools" -description = 'Build docker image for developt' +description = 'Build docker image for devcontainer' script = [ - "docker build . --tag wait-other-jobs:latest --file Dockerfile", + "docker build . --tag wait-other-jobs:latest --file .devcontainer/Dockerfile", ] [tasks.help] @@ -93,6 +94,7 @@ script = [ "dprint --version", # Returnes NON 0, why...? :< # "nixpkgs-fmt --version", + "hadolint --version", ] [tasks.check_no_git_diff] diff --git a/default.nix b/default.nix index 8b9ba139..f4e449c1 100644 --- a/default.nix +++ b/default.nix @@ -8,5 +8,6 @@ pkgs.mkShell { pkgs.cargo-make pkgs.nil pkgs.nixpkgs-fmt + pkgs.hadolint ]; } From 5f4f7701b36be4801805ecab9514b8f5e549637a Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Mon, 26 Jun 2023 18:48:11 +0900 Subject: [PATCH 07/34] Looks like hadolint action does not consider dotfiles in file glob --- .github/workflows/hadolint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/hadolint.yml b/.github/workflows/hadolint.yml index 0aae78c7..ca70b062 100644 --- a/.github/workflows/hadolint.yml +++ b/.github/workflows/hadolint.yml @@ -21,3 +21,4 @@ jobs: - uses: hadolint/hadolint-action@v3.1.0 with: recursive: 'true' + dockerfile: .devcontainer/Dockerfile From 26c2a00f03c1b28f017694fa31bae0662af30b24 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Mon, 26 Jun 2023 18:49:41 +0900 Subject: [PATCH 08/34] Remove testing code because of checked the hadolint behabvior in CI --- .devcontainer/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9250a1d5..30679c20 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,9 +10,6 @@ WORKDIR /home/vscode/sandbox # The install scripts will be syntax error if it will be eval with dash SHELL ["/bin/bash", "-c"] -# TODO: Remove this line. After checked the hadolint correctly alerts -RUN cd /tmp - # daemon mode required systemd, docker disables it # As I understand the definition https://hub.docker.com/r/nixos/nix/dockerfile at Nix 2.17, it looks like a single user installation(no-daemon) # See https://github.com/NixOS/nix/blob/fd4f03b8fdcb0f33552730c786139019e29f5dbe/scripts/install-nix-from-closure.sh#L129-L139 From 9b15d53dd901990868ab61609dfc759510fbbb85 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 00:01:10 +0900 Subject: [PATCH 09/34] Finish basic of devcontainer...! --- .devcontainer/Dockerfile | 27 ++++++++++++++++++--------- .devcontainer/README.md | 11 +++++++++++ .devcontainer/bootstrap.bash | 5 +++-- .devcontainer/devcontainer.json | 6 +++++- .devcontainer/setup_direnv.bash | 4 ++++ .vscode/settings.json | 1 - CONTRIBUTING.md | 20 ++++++++------------ Makefile.toml | 9 ++++++++- 8 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 .devcontainer/README.md create mode 100755 .devcontainer/setup_direnv.bash diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 30679c20..18ecacf1 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -5,6 +5,8 @@ FROM mcr.microsoft.com/devcontainers/base:ubuntu # Above microsoft image includes this user USER vscode +# This just uses for following build steps. +# vscode will set the WORKDIR into `/workspaces/wait-other-job` WORKDIR /home/vscode/sandbox # The install scripts will be syntax error if it will be eval with dash @@ -17,16 +19,23 @@ RUN bash <(curl -L https://nixos.org/nix/install) --no-daemon --yes ENV PATH /home/vscode/.nix-profile/bin:$PATH +# Basically do NOT merge files in COPY to prefer inline cache benefit + # Make sure the building phase done. To cache. `nix-build --no-out-link` does similar, but it skips bash. # NOTE: This does not mean the entry point is in nix-shell. -COPY ["../default.nix", "../Makefile.toml", "../package.json", "../package-lock.json", "./"] +COPY ["../default.nix", "./"] # Do no include like `npm install` here. Cuurently I don't cache it in container -RUN nix-channel --update && nix-shell --run 'echo "Welcome to this project :)"' -COPY ["../.envrc", "./"] -RUN nix-shell --run 'direnv allow' -COPY ["./.devcontainer/bootstrap.bash", "./"] -RUN ./bootstrap.bash - -# This can be skipped if you specify `docker run -it wait-other-jobs:ubuntu bash`. Also skipped in devcontainer, Use postCreateCommand instead. -# CMD nix-shell --command zsh +RUN nix-channel --update && nix-shell --run 'echo "Keep this line to build nix environment in this phase"' + +COPY ["./.devcontainer/setup_direnv.bash", "./"] +RUN ./setup_direnv.bash + +# Clean up to avoid confusion +# hadolint ignore=DL3059 +RUN rm ./default.nix ./setup_direnv.bash + +# `ENTRYPOINT` and `CMD` will be ignored in .devcontainer. Use postCreateCommand instead +# To simulate in docker, following CMD requires to specify PWD with repository files. Check `makers docker-shell` +# CMD nix-shell --run 'direnv allow && makers setup' && zsh +CMD ["./.devcontainer/bootstrap.bash"] diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 00000000..1dea1aaa --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,11 @@ +## How to update path for each extentions of devcontainer.json? + +Like this. + +```console +nix-instantiate --eval -E '(import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/4ef0dd85324fca49bf06fd9f2d52711503b1128c.tar.gz") {}).pkgs.dprint.outPath' | tr -d '"' +``` + +You should update them after updating fetchTarball path in default.nix + +I want to realize better integration, but I don't know it. diff --git a/.devcontainer/bootstrap.bash b/.devcontainer/bootstrap.bash index 61fed050..0fdb5646 100755 --- a/.devcontainer/bootstrap.bash +++ b/.devcontainer/bootstrap.bash @@ -1,2 +1,3 @@ -echo 'eval "$(nix-shell --run '"'"'direnv hook bash'"'"')"' >> ~/.bashrc -echo 'eval "$(nix-shell --run '"'"'direnv hook zsh'"'"')"' >> ~/.zshrc +#!/usr/bin/env bash + +nix-shell --run 'direnv allow && makers setup' && zsh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 91704330..7509b7a3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,12 +4,16 @@ "context": ".." }, "remoteUser": "vscode", + "userEnvProbe": "loginShell", + "postCreateCommand": "nix-shell --run 'direnv allow && makers setup'", + "postStartCommand": "zsh", "customizations": { "vscode": { "settings": { - "typescript.tsdk": "node_modules/typescript/lib", "editor.defaultFormatter": "dprint.dprint", "editor.formatOnSave": true, + "hadolint.hadolintPath": "/nix/store/3lrlw90virfykpbxv4n1mbap0g8593r5-hadolint-2.12.0/bin/hadolint", + "dprint.path": "/nix/store/6rzbms3q4p7yfp56c9vcr9ip83r1rl8m-dprint-0.36.1/bin/dprint", "[nix]": { "editor.defaultFormatter": "jnoortheen.nix-ide" }, diff --git a/.devcontainer/setup_direnv.bash b/.devcontainer/setup_direnv.bash new file mode 100755 index 00000000..b248a80f --- /dev/null +++ b/.devcontainer/setup_direnv.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +echo 'eval "$(nix-shell --run '"'"'direnv hook bash'"'"')"' >> ~/.bashrc +echo 'eval "$(nix-shell --run '"'"'direnv hook zsh'"'"')"' >> ~/.zshrc diff --git a/.vscode/settings.json b/.vscode/settings.json index 27589c6f..bd5059b7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { - "typescript.tsdk": "node_modules/typescript/lib", "editor.defaultFormatter": "dprint.dprint", "editor.formatOnSave": true, "[nix]": { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dad403ba..65286265 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,21 +13,17 @@ (prepared bash) ``` -### Docker +### Devcontainer/Docker -You can use Docker to skip installing Nix on your local machine. +You can use Devcontainer or the Docker to skip installing Nix on your local machine.\ +Simulate devcontainer from docker as following. ```console -> docker run --interactive --tty --rm --volume "$(pwd):$(pwd)" --workdir "$(pwd)" nixos/nix nix-shell -[nix-shell:/home/YOUR_NAME/wait-other-jobs]# -``` - -Or use cached builds. - -```console -> docker pull kachick/wait-other-jobs -> docker run --interactive --tty --rm --volume "$(pwd):$(pwd)" --workdir "$(pwd)" kachick/wait-other-jobs nix-shell -[nix-shell:/home/YOUR_NAME/wait-other-jobs]# +> docker build . --tag wait-other-jobs:latest --file .devcontainer/Dockerfile +> docker run --interactive --tty --rm --volume "$(pwd):/workspaces/wait-other-job" --workdir "/workspaces/wait-other-job" wait-other-jobs:latest +vscode ➜ /workspaces/wait-other-job (main) $ +vscode ➜ /workspaces/wait-other-job (main) $ makers check +...Done in... ``` ### Tasks diff --git a/Makefile.toml b/Makefile.toml index 42cc823d..d34706e0 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -71,13 +71,20 @@ category = "Tools" description = 'Parallel runner for all tests and linters' run_task = { name = ["typecheck", "test-ts", "test-js", "lint-check"], parallel = true } -[tasks.build-docker] +[tasks.docker-build] category = "Tools" description = 'Build docker image for devcontainer' script = [ "docker build . --tag wait-other-jobs:latest --file .devcontainer/Dockerfile", ] +[tasks.docker-shell] +category = "Tools" +description = 'Login to built container' +script = [ + "docker run --interactive --tty --rm --volume \"$(pwd):/workspaces/wait-other-job\" --workdir \"/workspaces/wait-other-job\" wait-other-jobs:latest", +] + [tasks.help] category = "Tools" description = 'Might help you - (This one)' From 1e21a0e471521a4759f6cd8abba30d674479262c Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 00:10:24 +0900 Subject: [PATCH 10/34] Add devcontainer CI --- .devcontainer/devcontainer.json | 1 + .github/workflows/ci-devcontainer.yml | 27 +++++++++++++++++++++++++++ .vscode/extensions.json | 1 + 3 files changed, 29 insertions(+) create mode 100644 .github/workflows/ci-devcontainer.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7509b7a3..89bdc9dd 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -33,6 +33,7 @@ ] }, "extensions": [ + "github.vscode-github-actions", "dbaeumer.vscode-eslint", "redhat.vscode-yaml", "editorconfig.editorconfig", diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml new file mode 100644 index 00000000..70e6094a --- /dev/null +++ b/.github/workflows/ci-devcontainer.yml @@ -0,0 +1,27 @@ +name: 'CI - Devcontainer' +on: + push: + branches: [main] + paths: + - '.devcontainer/**' + - '.github/workflows/ci-devcontainer.yml' + - '*.nix' + - 'Makefile.toml' + - '**vscode**' + pull_request: + paths: + - '.devcontainer/**' + - '.github/workflows/ci-devcontainer.yml' + - '*.nix' + - 'Makefile.toml' + - '**vscode**' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build and run dev container task + uses: devcontainers/ci@v0.3 + with: + runCmd: makers help && makers setup && makers versions && makers check diff --git a/.vscode/extensions.json b/.vscode/extensions.json index a800e7c0..365f3b56 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,6 @@ { "recommendations": [ + "github.vscode-github-actions", "dbaeumer.vscode-eslint", "redhat.vscode-yaml", "editorconfig.editorconfig", From d1571acc62e27e33b43f0e4bf5a8752d7f8036bb Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 00:12:25 +0900 Subject: [PATCH 11/34] Enable scheduled trigger for container CI --- .github/workflows/ci-devcontainer.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 70e6094a..8ab31ce5 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -15,6 +15,10 @@ on: - '*.nix' - 'Makefile.toml' - '**vscode**' + schedule: + # About JST 8:00 + - cron: '0 17 * * *' + workflow_dispatch: jobs: build: From 4d01d2b8d24187bf53cec96604874b23276d7866 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 00:19:41 +0900 Subject: [PATCH 12/34] Try the PATH setting https://github.com/devcontainers/ci/blob/cc80b0ef439af5f89482a346a8362cfb815cd3ca/docs/github-action.md#remoteenv --- .devcontainer/devcontainer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 89bdc9dd..76ea99c6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,6 +7,9 @@ "userEnvProbe": "loginShell", "postCreateCommand": "nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", + "remoteEnv": { + "PATH": "${localEnv:PATH}" + }, "customizations": { "vscode": { "settings": { From 99474aefb3b2153a336fca210eae5080a0207b8c Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 00:27:37 +0900 Subject: [PATCH 13/34] I dont know why bin/sh used only in CI... --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 76ea99c6..4142c072 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ }, "remoteUser": "vscode", "userEnvProbe": "loginShell", - "postCreateCommand": "nix-shell --run 'direnv allow && makers setup'", + "postCreateCommand": "/home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", "remoteEnv": { "PATH": "${localEnv:PATH}" From cabc9aaee5f5167a7721557039141ac295bac0b1 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 00:28:30 +0900 Subject: [PATCH 14/34] Remove outdaetd code --- .devcontainer/devcontainer.json | 3 --- dprint.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4142c072..cdf32f9a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,9 +7,6 @@ "userEnvProbe": "loginShell", "postCreateCommand": "/home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", - "remoteEnv": { - "PATH": "${localEnv:PATH}" - }, "customizations": { "vscode": { "settings": { diff --git a/dprint.json b/dprint.json index fd4643ff..4b2388db 100644 --- a/dprint.json +++ b/dprint.json @@ -13,7 +13,7 @@ "printWidth": 120, "singleQuote": true }, - "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,dockerfile,yml}", "**/Dockerfile"], + "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,yml}"], "excludes": ["**/node_modules", "**/*-lock.json", "lib/**", "dist/**"], "plugins": [ "https://plugins.dprint.dev/typescript-0.85.0.wasm", From 104254426bec3dfeb02f807595c703a09e1b94e6 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 00:48:47 +0900 Subject: [PATCH 15/34] Give it a try! https://discourse.nixos.org/t/per-user-profiles-not-created-when-home-mounted-on-nfs/5864/2 --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cdf32f9a..f9630d4c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ }, "remoteUser": "vscode", "userEnvProbe": "loginShell", - "postCreateCommand": "/home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", + "postCreateCommand": "mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/vscode && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", "customizations": { "vscode": { From ed5a3ae496bf6195bb586e3cb1e4e671a9515d85 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 01:17:48 +0900 Subject: [PATCH 16/34] Add debug log --- .devcontainer/bootstrap.bash | 5 ++++- .devcontainer/devcontainer.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.devcontainer/bootstrap.bash b/.devcontainer/bootstrap.bash index 0fdb5646..16c65cec 100755 --- a/.devcontainer/bootstrap.bash +++ b/.devcontainer/bootstrap.bash @@ -1,3 +1,6 @@ #!/usr/bin/env bash -nix-shell --run 'direnv allow && makers setup' && zsh +whoami && ls -alh /nix && \ + mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/vscode && \ + nix-shell --run 'direnv allow && makers setup' && \ + zsh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f9630d4c..81ae49ad 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ }, "remoteUser": "vscode", "userEnvProbe": "loginShell", - "postCreateCommand": "mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/vscode && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", + "postCreateCommand": "whoami && ls -alh /nix && mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/vscode && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", "customizations": { "vscode": { From 206e8adf214f55b55da6662a4b0f4129208df0f0 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 01:32:28 +0900 Subject: [PATCH 17/34] Looks like a same issue of https://github.com/devcontainers/ci/issues/176#issuecomment-1291232544 --- .github/workflows/ci-devcontainer.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 8ab31ce5..6794b43e 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -28,4 +28,6 @@ jobs: - name: Build and run dev container task uses: devcontainers/ci@v0.3 with: + # https://github.com/devcontainers/ci/issues/176#issuecomment-1291232544 + skipContainerUserIdUpdate: true runCmd: makers help && makers setup && makers versions && makers check From af54fc382a11eed22e590f6a410fd843f72230e8 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 01:41:11 +0900 Subject: [PATCH 18/34] We drop the mkdir phase again --- .devcontainer/bootstrap.bash | 1 - .devcontainer/devcontainer.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.devcontainer/bootstrap.bash b/.devcontainer/bootstrap.bash index 16c65cec..080a4bff 100755 --- a/.devcontainer/bootstrap.bash +++ b/.devcontainer/bootstrap.bash @@ -1,6 +1,5 @@ #!/usr/bin/env bash whoami && ls -alh /nix && \ - mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/vscode && \ nix-shell --run 'direnv allow && makers setup' && \ zsh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 81ae49ad..1ca9dee2 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ }, "remoteUser": "vscode", "userEnvProbe": "loginShell", - "postCreateCommand": "whoami && ls -alh /nix && mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/vscode && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", + "postCreateCommand": "whoami && ls -alh /nix && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", "customizations": { "vscode": { From 481643a9cbded242b1d6768f86c1546d7cdbc26d Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 04:39:35 +0900 Subject: [PATCH 19/34] Prefer 22.04 --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 18ecacf1..1931834c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,6 +1,6 @@ # Do not use `FROM nixos/nix`. It cannot use `groupadd` even not the NixOS # See https://stackoverflow.com/questions/75653182/why-do-some-official-nix-docker-containers-not-have-the-nixos-rebuild-command -FROM mcr.microsoft.com/devcontainers/base:ubuntu +FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04 # Above microsoft image includes this user USER vscode From 826963d2819a89de49cfadcdfc10e73565e3ac9e Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 13:20:39 +0900 Subject: [PATCH 20/34] Give it a try! (I guess, this will fail) --- .devcontainer/Dockerfile | 1 + .github/workflows/ci-devcontainer.yml | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1931834c..f4272a64 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -16,6 +16,7 @@ SHELL ["/bin/bash", "-c"] # As I understand the definition https://hub.docker.com/r/nixos/nix/dockerfile at Nix 2.17, it looks like a single user installation(no-daemon) # See https://github.com/NixOS/nix/blob/fd4f03b8fdcb0f33552730c786139019e29f5dbe/scripts/install-nix-from-closure.sh#L129-L139 RUN bash <(curl -L https://nixos.org/nix/install) --no-daemon --yes +RUN chgrp "$USER" /nix ENV PATH /home/vscode/.nix-profile/bin:$PATH diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 6794b43e..8ab31ce5 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -28,6 +28,4 @@ jobs: - name: Build and run dev container task uses: devcontainers/ci@v0.3 with: - # https://github.com/devcontainers/ci/issues/176#issuecomment-1291232544 - skipContainerUserIdUpdate: true runCmd: makers help && makers setup && makers versions && makers check From 051525ff7317a500dac4424a67e06f7402910923 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 13:55:31 +0900 Subject: [PATCH 21/34] I am tired https://medium.com/@guillem.riera/making-visual-studio-code-devcontainer-work-properly-on-rootless-podman-8d9ddc368b30 --- .devcontainer/Dockerfile | 1 - .devcontainer/devcontainer.json | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index f4272a64..1931834c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -16,7 +16,6 @@ SHELL ["/bin/bash", "-c"] # As I understand the definition https://hub.docker.com/r/nixos/nix/dockerfile at Nix 2.17, it looks like a single user installation(no-daemon) # See https://github.com/NixOS/nix/blob/fd4f03b8fdcb0f33552730c786139019e29f5dbe/scripts/install-nix-from-closure.sh#L129-L139 RUN bash <(curl -L https://nixos.org/nix/install) --no-daemon --yes -RUN chgrp "$USER" /nix ENV PATH /home/vscode/.nix-profile/bin:$PATH diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1ca9dee2..2f0ca0de 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,6 +4,11 @@ "context": ".." }, "remoteUser": "vscode", + "containerUser": "vscode", + "updateRemoteUserUID": true, + "containerEnv": { + "HOME": "/home/vscode" + }, "userEnvProbe": "loginShell", "postCreateCommand": "whoami && ls -alh /nix && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", From 471efad31f5c3db35fd671f6883970b99801346c Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 14:16:26 +0900 Subject: [PATCH 22/34] Add more debugg logging --- .devcontainer/bootstrap.bash | 2 +- .devcontainer/devcontainer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/bootstrap.bash b/.devcontainer/bootstrap.bash index 080a4bff..54a3a639 100755 --- a/.devcontainer/bootstrap.bash +++ b/.devcontainer/bootstrap.bash @@ -1,5 +1,5 @@ #!/usr/bin/env bash -whoami && ls -alh /nix && \ +whoami && cat /etc/passwd && ls -alh /nix && \ nix-shell --run 'direnv allow && makers setup' && \ zsh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2f0ca0de..fafd012f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,7 +10,7 @@ "HOME": "/home/vscode" }, "userEnvProbe": "loginShell", - "postCreateCommand": "whoami && ls -alh /nix && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", + "postCreateCommand": "whoami && cat /etc/passwd && ls -alh /nix && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", "customizations": { "vscode": { From feca185e2cadbd57eb500d7cf31482803ff0950d Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 14:46:32 +0900 Subject: [PATCH 23/34] Revert 826963d2819a89de49cfadcdfc10e73565e3ac9e --- .github/workflows/ci-devcontainer.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 8ab31ce5..6794b43e 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -28,4 +28,6 @@ jobs: - name: Build and run dev container task uses: devcontainers/ci@v0.3 with: + # https://github.com/devcontainers/ci/issues/176#issuecomment-1291232544 + skipContainerUserIdUpdate: true runCmd: makers help && makers setup && makers versions && makers check From 87431708caa5dbddbcca5febe39c48e8c30846af Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 14:48:04 +0900 Subject: [PATCH 24/34] I am a new in debugger; --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fafd012f..31fff3d6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,7 +10,7 @@ "HOME": "/home/vscode" }, "userEnvProbe": "loginShell", - "postCreateCommand": "whoami && cat /etc/passwd && ls -alh /nix && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", + "postCreateCommand": "whoami && cat /etc/passwd && ls -alh /nix && ls -alh . && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", "postStartCommand": "zsh", "customizations": { "vscode": { From 4a497cf3150720c744478bd45c3ecc7d4d746c10 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 14:55:37 +0900 Subject: [PATCH 25/34] Persially revert 051525ff7317a500dac4424a67e06f7402910923 --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 31fff3d6..e480a04d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ }, "remoteUser": "vscode", "containerUser": "vscode", - "updateRemoteUserUID": true, + "updateRemoteUserUID": false, "containerEnv": { "HOME": "/home/vscode" }, From 23b7f15e4ee5a69a32d056b01ab4b8574fd6871e Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 18:04:27 +0900 Subject: [PATCH 26/34] Update UID/GID with hostmachine before installing NIX --- .devcontainer/Dockerfile | 9 ++++++++- .devcontainer/bootstrap.bash | 3 ++- .devcontainer/devcontainer.json | 10 +++++++--- .devcontainer/docker_build.bash | 3 +++ .devcontainer/docker_shell.bash | 3 +++ .github/workflows/ci-devcontainer.yml | 13 +++++++++++-- Makefile.toml | 4 ++-- 7 files changed, 36 insertions(+), 9 deletions(-) create mode 100755 .devcontainer/docker_build.bash create mode 100755 .devcontainer/docker_shell.bash diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1931834c..b5ec4aaa 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,7 +2,14 @@ # See https://stackoverflow.com/questions/75653182/why-do-some-official-nix-docker-containers-not-have-the-nixos-rebuild-command FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04 -# Above microsoft image includes this user +# Above microsoft image contains to create vscode user + +# Use same UID/GID to avoid mount and nix path permission issues +ARG container_user_uid +ARG container_user_gid +RUN usermod -u $container_user_uid vscode && groupmod -g $container_user_gid vscode + +# Switching the user should be after the changed IDs USER vscode # This just uses for following build steps. diff --git a/.devcontainer/bootstrap.bash b/.devcontainer/bootstrap.bash index 54a3a639..b8feb32d 100755 --- a/.devcontainer/bootstrap.bash +++ b/.devcontainer/bootstrap.bash @@ -1,5 +1,6 @@ #!/usr/bin/env bash -whoami && cat /etc/passwd && ls -alh /nix && \ + +whoami && id && cat /etc/passwd && ls -alh /nix && ls -alh . && \ nix-shell --run 'direnv allow && makers setup' && \ zsh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e480a04d..1ac72841 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,20 @@ { "build": { "dockerfile": "Dockerfile", - "context": ".." + "context": "..", + "args": { + "container_user_uid": "${localEnv:container_user_uid:1000}", + "container_user_gid": "${localEnv:container_user_gid:1000}" + } }, "remoteUser": "vscode", "containerUser": "vscode", - "updateRemoteUserUID": false, + "updateRemoteUserUID": true, "containerEnv": { "HOME": "/home/vscode" }, "userEnvProbe": "loginShell", - "postCreateCommand": "whoami && cat /etc/passwd && ls -alh /nix && ls -alh . && /home/vscode/.nix-profile/bin/nix-shell --run 'direnv allow && makers setup'", + "postCreateCommand": "./.devcontainer/bootstrap.bash", "postStartCommand": "zsh", "customizations": { "vscode": { diff --git a/.devcontainer/docker_build.bash b/.devcontainer/docker_build.bash new file mode 100755 index 00000000..325aefd5 --- /dev/null +++ b/.devcontainer/docker_build.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker build . --tag wait-other-jobs:latest --build-arg container_user_uid="$(stat -c '%u' .)" --build-arg container_user_gid="$(stat -c '%g' .)" --file .devcontainer/Dockerfile diff --git a/.devcontainer/docker_shell.bash b/.devcontainer/docker_shell.bash new file mode 100755 index 00000000..cac87680 --- /dev/null +++ b/.devcontainer/docker_shell.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker run --interactive --tty --rm --volume "$(pwd):/workspaces/wait-other-job" --workdir "/workspaces/wait-other-job" wait-other-jobs:latest diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 6794b43e..82b42d70 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -25,9 +25,18 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Log host users and file owners + run: | + whoami + id + ls -alh + - name: Set UID and GID as ENV from repository files + run: | + uid="$(stat -c '%u' .)" + gid="$(stat -c '%g' .)" + echo "container_user_uid=${uid}" | tee -a "$GITHUB_ENV" + echo "container_user_gid=${gid}" | tee -a "$GITHUB_ENV" - name: Build and run dev container task uses: devcontainers/ci@v0.3 with: - # https://github.com/devcontainers/ci/issues/176#issuecomment-1291232544 - skipContainerUserIdUpdate: true runCmd: makers help && makers setup && makers versions && makers check diff --git a/Makefile.toml b/Makefile.toml index d34706e0..7c3bea0d 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -75,14 +75,14 @@ run_task = { name = ["typecheck", "test-ts", "test-js", "lint-check"], parallel category = "Tools" description = 'Build docker image for devcontainer' script = [ - "docker build . --tag wait-other-jobs:latest --file .devcontainer/Dockerfile", + "./.devcontainer/docker_build.bash", ] [tasks.docker-shell] category = "Tools" description = 'Login to built container' script = [ - "docker run --interactive --tty --rm --volume \"$(pwd):/workspaces/wait-other-job\" --workdir \"/workspaces/wait-other-job\" wait-other-jobs:latest", + "./.devcontainer/docker_shell.bash", ] [tasks.help] From 2a63dd7b121e90367144a5305602a72ea6cea300 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 18:21:43 +0900 Subject: [PATCH 27/34] Fix missing commit --- .devcontainer/Dockerfile | 4 ++-- .devcontainer/bootstrap.bash | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b5ec4aaa..65c16162 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -44,5 +44,5 @@ RUN rm ./default.nix ./setup_direnv.bash # `ENTRYPOINT` and `CMD` will be ignored in .devcontainer. Use postCreateCommand instead # To simulate in docker, following CMD requires to specify PWD with repository files. Check `makers docker-shell` -# CMD nix-shell --run 'direnv allow && makers setup' && zsh -CMD ["./.devcontainer/bootstrap.bash"] +ENTRYPOINT ["./.devcontainer/bootstrap.bash"] +CMD ["zsh"] diff --git a/.devcontainer/bootstrap.bash b/.devcontainer/bootstrap.bash index b8feb32d..a83970d3 100755 --- a/.devcontainer/bootstrap.bash +++ b/.devcontainer/bootstrap.bash @@ -1,6 +1,4 @@ #!/usr/bin/env bash - whoami && id && cat /etc/passwd && ls -alh /nix && ls -alh . && \ - nix-shell --run 'direnv allow && makers setup' && \ - zsh + nix-shell --run 'direnv allow && makers setup' From 48e41e8606dda50656055a680e435ef4b13bbdda Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 18:22:57 +0900 Subject: [PATCH 28/34] Restrict with whole timeout-minutes --- .github/workflows/ci-devcontainer.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 82b42d70..754f9f9d 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -22,6 +22,7 @@ on: jobs: build: + timeout-minutes: 30 runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 08743fc7523a9905aa3c08c96b6b226be08cf340 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 18:34:23 +0900 Subject: [PATCH 29/34] Is this the correct shell specifier? --- .devcontainer/devcontainer.json | 10 ++++++++-- .vscode/extensions.json | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1ac72841..1a03007b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,10 +15,15 @@ }, "userEnvProbe": "loginShell", "postCreateCommand": "./.devcontainer/bootstrap.bash", - "postStartCommand": "zsh", "customizations": { "vscode": { "settings": { + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "/usr/bin/zsh" + } + }, + "terminal.integrated.defaultProfile.linux": "zsh", "editor.defaultFormatter": "dprint.dprint", "editor.formatOnSave": true, "hadolint.hadolintPath": "/nix/store/3lrlw90virfykpbxv4n1mbap0g8593r5-hadolint-2.12.0/bin/hadolint", @@ -49,7 +54,8 @@ "dprint.dprint", "jnoortheen.nix-ide", "tamasfe.even-better-toml", - "exiasr.hadolint" + "exiasr.hadolint", + "ms-azuretools.vscode-docker" ] } } diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 365f3b56..b23393e1 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,6 +7,7 @@ "dprint.dprint", "jnoortheen.nix-ide", "tamasfe.even-better-toml", - "exiasr.hadolint" + "exiasr.hadolint", + "ms-azuretools.vscode-docker" ] } From 5b4025f2ff791e7f0ff46f5ddc908b21912ed909 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 18:54:01 +0900 Subject: [PATCH 30/34] This action can not simulate actuall devcontainer use :< --- .github/workflows/ci-devcontainer.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 754f9f9d..15022785 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -40,4 +40,5 @@ jobs: - name: Build and run dev container task uses: devcontainers/ci@v0.3 with: - runCmd: makers help && makers setup && makers versions && makers check + # Can't we call these comands on the nix-shell even enabled direnv...? + runCmd: nix-shell -run 'makers help && makers versions && makers check' From 3c14af562fd1a18cafd5b46893eaffe776beea82 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 18:55:27 +0900 Subject: [PATCH 31/34] `git checkout main dprint.json` --- dprint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dprint.json b/dprint.json index 489e0822..6457e9df 100644 --- a/dprint.json +++ b/dprint.json @@ -13,7 +13,7 @@ "printWidth": 120, "singleQuote": true }, - "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,yml}"], + "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,yml,toml}"], "excludes": ["**/node_modules", "**/*-lock.json", "lib/**", "dist/**"], "plugins": [ "https://plugins.dprint.dev/typescript-0.85.1.wasm", From 31c3820fd417d54150c12fa10a4cc3ac843c2503 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 18:57:08 +0900 Subject: [PATCH 32/34] Fix a typo --- .github/workflows/ci-devcontainer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-devcontainer.yml b/.github/workflows/ci-devcontainer.yml index 15022785..245decb1 100644 --- a/.github/workflows/ci-devcontainer.yml +++ b/.github/workflows/ci-devcontainer.yml @@ -41,4 +41,4 @@ jobs: uses: devcontainers/ci@v0.3 with: # Can't we call these comands on the nix-shell even enabled direnv...? - runCmd: nix-shell -run 'makers help && makers versions && makers check' + runCmd: nix-shell --run 'makers help && makers versions && makers check' From f8c454ac78ca777d140fd3e32d517534d59e30f6 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 19:09:35 +0900 Subject: [PATCH 33/34] Fix merge miss --- default.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/default.nix b/default.nix index e25d69d4..8e1501af 100644 --- a/default.nix +++ b/default.nix @@ -8,10 +8,7 @@ pkgs.mkShell { pkgs.cargo-make pkgs.nil pkgs.nixpkgs-fmt -<<<<<<< HEAD - pkgs.hadolint -======= pkgs.actionlint ->>>>>>> main + pkgs.hadolint ]; } From 34cec690f3a1281a32de3cdb379d470e19f71c37 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 27 Jun 2023 21:51:37 +0900 Subject: [PATCH 34/34] Update docs --- CONTRIBUTING.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65286265..8c883778 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,12 +15,15 @@ ### Devcontainer/Docker -You can use Devcontainer or the Docker to skip installing Nix on your local machine.\ +You can use Devcontainer or the Docker to skip installing Nix on your local machine. + +[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/kachick/vwait-other-jobs) 🚶 + Simulate devcontainer from docker as following. ```console -> docker build . --tag wait-other-jobs:latest --file .devcontainer/Dockerfile -> docker run --interactive --tty --rm --volume "$(pwd):/workspaces/wait-other-job" --workdir "/workspaces/wait-other-job" wait-other-jobs:latest +> ./.devcontainer/docker_build.bash +> ./.devcontainer/docker_shell.bash vscode ➜ /workspaces/wait-other-job (main) $ vscode ➜ /workspaces/wait-other-job (main) $ makers check ...Done in...