diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..2eed142bc8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +# Ignore all files and folders +** + +# Include flake.nix and flake.lock +!flake.nix +!flake.lock diff --git a/.github/workflows/dogfood.yaml b/.github/workflows/dogfood.yaml index 751eaaa913..fa328a0b52 100644 --- a/.github/workflows/dogfood.yaml +++ b/.github/workflows/dogfood.yaml @@ -7,10 +7,14 @@ on: paths: - "dogfood/**" - ".github/workflows/dogfood.yaml" + - "flake.lock" + - "flake.nix" pull_request: paths: - "dogfood/**" - ".github/workflows/dogfood.yaml" + - "flake.lock" + - "flake.nix" workflow_dispatch: jobs: @@ -45,7 +49,7 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Build and push + - name: Build and push Non-Nix image uses: depot/build-push-action@v1 with: project: b4q6ltmpzh @@ -53,9 +57,23 @@ jobs: buildx-fallback: true context: "{{defaultContext}}:dogfood" pull: true + save: true push: ${{ github.ref == 'refs/heads/main' }} tags: "codercom/oss-dogfood:${{ steps.docker-tag-name.outputs.tag }},codercom/oss-dogfood:latest" + - name: Build and push Nix image + uses: depot/build-push-action@v1 + with: + project: b4q6ltmpzh + token: ${{ secrets.DEPOT_TOKEN }} + buildx-fallback: true + context: "." + file: "dogfood/Dockerfile.nix" + pull: true + save: true + push: ${{ github.ref == 'refs/heads/main' }} + tags: "codercom/oss-dogfood-nix:${{ steps.docker-tag-name.outputs.tag }},codercom/oss-dogfood-nix:latest" + deploy_template: needs: build_image runs-on: ubuntu-latest diff --git a/dogfood/Dockerfile.nix b/dogfood/Dockerfile.nix new file mode 100644 index 0000000000..40729eb9c5 --- /dev/null +++ b/dogfood/Dockerfile.nix @@ -0,0 +1,42 @@ +# Build stage +FROM nixos/nix:2.19.2 as nix + +# enable --experimental-features 'nix-command flakes' globally +# nix does not enable these features by default these are required to run commands like +# nix develop -c 'some command' or to use falke.nix +RUN mkdir -p /etc/nix && \ + echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf + +# Copy Nix flake and install dependencies +COPY flake.* /app/ +RUN nix profile install "/app#all" --priority 4 && \ + rm -rf /app && \ + nix-collect-garbage -d + +# Final image +FROM codercom/enterprise-base:latest as final + +# Set the non-root user +USER root + +# Copy the Nix related files into the Docker image +COPY --from=nix --chown=coder:coder /nix /nix +COPY --from=nix /etc/nix /etc/nix +COPY --from=nix --chown=coder:coder /root/.nix-profile /home/coder/.nix-profile +COPY --from=nix /etc/passwd /etc/passwd.nix +COPY --from=nix /etc/group /etc/group.nix + +# Merge the passwd and group files +# We need all nix users and groups to be available in the final image +RUN cat /etc/passwd.nix >> /etc/passwd && \ + cat /etc/group.nix >> /etc/group && \ + rm /etc/passwd.nix /etc/group.nix + +# Set environment variables and PATH +ENV PATH=/home/coder/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:$PATH \ + GOPRIVATE="coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder" \ + NODE_OPTIONS="--max-old-space-size=8192" + +# Set the user to 'coder' +USER coder +WORKDIR /home/coder diff --git a/dogfood/main.tf b/dogfood/main.tf index 87d3c841aa..8a638d314c 100644 --- a/dogfood/main.tf +++ b/dogfood/main.tf @@ -34,7 +34,6 @@ locals { repo_base_dir = replace(data.coder_parameter.repo_base_dir.value, "/^~\\//", "/home/coder/") repo_dir = module.git-clone.repo_dir container_name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}" - registry_name = "codercom/oss-dogfood" jfrog_host = replace(var.jfrog_url, "https://", "") } @@ -46,6 +45,23 @@ data "coder_parameter" "repo_base_dir" { mutable = true } +data "coder_parameter" "image_type" { + type = "string" + name = "Coder Image" + default = "codercom/oss-dogfood:latest" + description = "The Docker image used to run your workspace. Choose between nix and non-nix images." + option { + icon = "/icon/coder.svg" + name = "Non-Nix" + value = "codercom/oss-dogfood:latest" + } + option { + icon = "/icons/nix.svg" + name = "Nix" + value = "codercom/oss-dogfood-nix:latest" + } +} + data "coder_parameter" "region" { type = "string" name = "Region" @@ -248,6 +264,9 @@ resource "coder_agent" "dev" { set -eux -o pipefail # Start Docker service sudo service docker start + # Install playwright dependencies + # We want to use the playwright version from site/package.json + cd "${local.repo_dir}/site" && pnpm install && pnpm playwright:install EOT } @@ -279,15 +298,16 @@ resource "docker_volume" "home_volume" { } data "docker_registry_image" "dogfood" { - name = "${local.registry_name}:latest" + name = data.coder_parameter.image_type.value } resource "docker_image" "dogfood" { - name = "${local.registry_name}@${data.docker_registry_image.dogfood.sha256_digest}" + name = "${data.coder_parameter.image_type.value}@${data.docker_registry_image.dogfood.sha256_digest}" pull_triggers = [ data.docker_registry_image.dogfood.sha256_digest, sha1(join("", [for f in fileset(path.module, "files/*") : filesha1(f)])), filesha1("Dockerfile"), + filesha1("Dockerfile.nix"), ] keep_locally = true } diff --git a/flake.lock b/flake.lock index 91839d2745..fe4bb7c34f 100644 --- a/flake.lock +++ b/flake.lock @@ -6,27 +6,30 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1655479430, - "narHash": "sha256-ZQgJFlrddH2uQDQepDFYy3C+Ik/geMQgGWkLVhA9wss=", + "lastModified": 1682005581, + "narHash": "sha256-mPaQg6bN1I6160RG4Yi3CjKNJ0oHoGYYxOSpOWHWXK0=", "owner": "storj", "repo": "drpc", - "rev": "0a6ae7bccab6f01ca6390a7a5bf9abeee71624d2", + "rev": "9716137f6037cde2f813985fcee00409b4101ed2", "type": "github" }, "original": { "owner": "storj", - "ref": "v0.0.32", + "ref": "v0.0.33", "repo": "drpc", "type": "github" } }, "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1634851050, - "narHash": "sha256-N83GlSGPJJdcqhUxSCS/WwW5pksYf3VP1M13cDRTSVA=", + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "owner": "numtide", "repo": "flake-utils", - "rev": "c91f3de5adaf1de973b797ef7485e441a65b8935", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", "type": "github" }, "original": { @@ -37,14 +40,14 @@ }, "flake-utils_2": { "inputs": { - "systems": "systems" + "systems": "systems_2" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", "type": "github" }, "original": { @@ -55,11 +58,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1635797866, - "narHash": "sha256-e3vqt720wyb1PPNcGXej8wwip2/tgO1JsSGYK1NptSw=", + "lastModified": 1681823821, + "narHash": "sha256-LGm3j7hW2C3T28q2/r49tX01zIyoaaQAJRi7rlISbr0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6751e7428f20328fed076acfcbb340d0f4aa0c07", + "rev": "9b419c67cfeb210d333fc0c34ae6e8c7a987d443", "type": "github" }, "original": { @@ -70,11 +73,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1704538339, - "narHash": "sha256-1734d3mQuux9ySvwf6axRWZRBhtcZA9Q8eftD6EZg6U=", + "lastModified": 1706550542, + "narHash": "sha256-UcsnCG6wx++23yeER4Hg18CXWbgNpqNXcHIo5/1Y+hc=", "owner": "nixos", "repo": "nixpkgs", - "rev": "46ae0210ce163b3cba6c7da08840c1d63de9c701", + "rev": "97b17f32362e475016f942bbdfda4a4a72a8a652", "type": "github" }, "original": { @@ -105,6 +108,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index f3322d9c77..08f9e5d7ec 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; - drpc.url = "github:storj/drpc/v0.0.32"; + drpc.url = "github:storj/drpc/v0.0.33"; }; outputs = { self, nixpkgs, flake-utils, drpc }: @@ -45,14 +45,11 @@ kubernetes-helm less # Needed for many LD system libs! - libuuid + util-linux mockgen nfpm nodejs nodejs.pkgs.pnpm - nodejs.pkgs.prettier - nodejs.pkgs.typescript - nodejs.pkgs.typescript-language-server openssh openssl pango @@ -78,10 +75,16 @@ zsh zstd ]; + + allPackages = pkgs.buildEnv { + name = "all-packages"; + paths = devShellPackages; + }; in { defaultPackage = formatter; # or replace it with your desired default package. devShell = pkgs.mkShell { buildInputs = devShellPackages; }; + packages.all = allPackages; } ); } diff --git a/site/src/theme/icons.json b/site/src/theme/icons.json index 7ea2f49323..de791cdd0c 100644 --- a/site/src/theme/icons.json +++ b/site/src/theme/icons.json @@ -54,6 +54,7 @@ "matlab.svg", "memory.svg", "microsoft.svg", + "nix.svg", "node.svg", "nodejs.svg", "nomad.svg", diff --git a/site/static/icon/nix.svg b/site/static/icon/nix.svg new file mode 100644 index 0000000000..a40c4f7418 --- /dev/null +++ b/site/static/icon/nix.svg @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file