diff --git a/.devcontainer/cache/before-cache.sh b/.devcontainer/cache/before-cache.sh index cfa7acc9d9579..9548a154c38d7 100755 --- a/.devcontainer/cache/before-cache.sh +++ b/.devcontainer/cache/before-cache.sh @@ -1,11 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash -# This file establishes a basline for the reposuitory before any steps in the "prepare.sh" +# This file establishes a basline for the repository before any steps in the "prepare.sh" # are run. Its just a find command that filters out a few things we don't need to watch. set -e -SCRIPT_PATH="$(cd "$(dirname $0)" && pwd)" +SCRIPT_PATH="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)" SOURCE_FOLDER="${1:-"."}" cd "${SOURCE_FOLDER}" diff --git a/.devcontainer/cache/build-cache-image.sh b/.devcontainer/cache/build-cache-image.sh index 42e143d7af437..9aee60fe5c13e 100755 --- a/.devcontainer/cache/build-cache-image.sh +++ b/.devcontainer/cache/build-cache-image.sh @@ -6,7 +6,7 @@ set -e -SCRIPT_PATH="$(cd "$(dirname $0)" && pwd)" +SCRIPT_PATH="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)" CONTAINER_IMAGE_REPOSITORY="$1" BRANCH="${2:-"main"}" diff --git a/.devcontainer/cache/cache-diff.sh b/.devcontainer/cache/cache-diff.sh index 362337ce6eb0f..3f8b77e5602b6 100755 --- a/.devcontainer/cache/cache-diff.sh +++ b/.devcontainer/cache/cache-diff.sh @@ -1,12 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash # This file is used to archive off a copy of any differences in the source tree into another location -# in the image. Once the codespace is up, this will be restored into its proper location (which is -# quick and happens parallel to other startup activities) +# in the image. Once the codespace / container is up, this will be restored into its proper location. set -e -SCRIPT_PATH="$(cd "$(dirname $0)" && pwd)" +SCRIPT_PATH="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)" SOURCE_FOLDER="${1:-"."}" CACHE_FOLDER="${2:-"/usr/local/etc/devcontainer-cache"}" diff --git a/.devcontainer/cache/cache.Dockerfile b/.devcontainer/cache/cache.Dockerfile index 79af3ee8a3553..c1af3337c2f77 100644 --- a/.devcontainer/cache/cache.Dockerfile +++ b/.devcontainer/cache/cache.Dockerfile @@ -1,7 +1,8 @@ # This dockerfile is used to build up from a base image to create an image with cached results of running "prepare.sh". # Other image contents: https://github.com/microsoft/vscode-dev-containers/blob/master/repository-containers/images/github.com/microsoft/vscode/.devcontainer/base.Dockerfile -FROM mcr.microsoft.com/vscode/devcontainers/repos/microsoft/vscode:dev +# First stage generates the cache tar +FROM mcr.microsoft.com/vscode/devcontainers/repos/microsoft/vscode:dev as cache ARG USERNAME=node COPY --chown=${USERNAME}:${USERNAME} . /repo-source-tmp/ RUN mkdir /usr/local/etc/devcontainer-cache \ @@ -10,5 +11,11 @@ RUN mkdir /usr/local/etc/devcontainer-cache \ cd /repo-source-tmp \ && .devcontainer/cache/before-cache.sh \ && .devcontainer/prepare.sh \ - && .devcontainer/cache/cache-diff.sh" \ - && rm -rf /repo-source-tmp + && .devcontainer/cache/cache-diff.sh" + +# Second stage is the acual output that includes only the tar - restore-diff.sh is then fired on postCreateCommand to expand it +FROM mcr.microsoft.com/vscode/devcontainers/repos/microsoft/vscode:dev as dev-container +ARG USERNAME=node +ARG CACHE_FOLDER="/usr/local/etc/devcontainer-cache" +RUN mkdir -p "${CACHE_FOLDER}" && chown "${USERNAME}:${USERNAME}" "${CACHE_FOLDER}" +COPY --from=cache ${CACHE_FOLDER}/cache.tar ${CACHE_FOLDER}/ diff --git a/.devcontainer/cache/restore-diff.sh b/.devcontainer/cache/restore-diff.sh index 2f418d8748092..88e25062fa5ab 100755 --- a/.devcontainer/cache/restore-diff.sh +++ b/.devcontainer/cache/restore-diff.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This file restores the results of the "prepare.sh" into their proper locations # once the container has been created. It runs as a postCreateCommand which diff --git a/.devcontainer/prepare.sh b/.devcontainer/prepare.sh index 47a77a533aecb..0a1af16cb95a4 100755 --- a/.devcontainer/prepare.sh +++ b/.devcontainer/prepare.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This file contains the steps that should be run when creating the intermediary image that contains # contents for that should be in the image by default. It will be used to build up from the base image