forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev container cache image generation
- Loading branch information
Showing
10 changed files
with
162 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.manifest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#/bin/bash | ||
|
||
# This file establishes a basline for the reposuitory 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)" | ||
SOURCE_FOLDER="${1:-"."}" | ||
|
||
cd "${SOURCE_FOLDER}" | ||
echo "[$(date)] Generating ""before"" manifest..." | ||
find -L . -not -path "*/.git/*" -and -not -path "${SCRIPT_PATH}/*.manifest" -type f > "${SCRIPT_PATH}/before.manifest" | ||
echo "[$(date)] Done!" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# This file simply wraps the dockeer build command used to build the image with the | ||
# cached result of the commands from "prepare.sh" and pushes it to the specified | ||
# container image registry. | ||
|
||
set -e | ||
|
||
SCRIPT_PATH="$(cd "$(dirname $0)" && pwd)" | ||
CONTAINER_IMAGE_REPOSITORY="$1" | ||
BRANCH="${2:-"master"}" | ||
|
||
if [ "${CONTAINER_IMAGE_REPOSITORY}" = "" ]; then | ||
echo "Container repository not specified!" | ||
exit 1 | ||
fi | ||
|
||
TAG="${BRANCH//\//-}" | ||
echo "[$(date)] ${BRANCH} => ${TAG}" | ||
cd "${SCRIPT_PATH}/../.." | ||
|
||
echo "[$(date)] Starting image build..." | ||
docker build -t ${CONTAINER_IMAGE_REPOSITORY}:"${TAG}" -f "${SCRIPT_PATH}/cache.Dockerfile" . | ||
echo "[$(date)] Image build complete." | ||
|
||
echo "[$(date)] Pushing image..." | ||
docker push ${CONTAINER_IMAGE_REPOSITORY}:"${TAG}" | ||
echo "[$(date)] Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/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) | ||
|
||
set -e | ||
|
||
SCRIPT_PATH="$(cd "$(dirname $0)" && pwd)" | ||
SOURCE_FOLDER="${1:-"."}" | ||
CACHE_FOLDER="${2:-"/usr/local/etc/devcontainer-cache"}" | ||
|
||
echo "[$(date)] Starting cache operation..." | ||
cd "${SOURCE_FOLDER}" | ||
echo "[$(date)] Determining diffs..." | ||
find -L . -not -path "*/.git/*" -and -not -path "${SCRIPT_PATH}/*.manifest" -type f > "${SCRIPT_PATH}/after.manifest" | ||
grep -Fxvf "${SCRIPT_PATH}/before.manifest" "${SCRIPT_PATH}/after.manifest" > "${SCRIPT_PATH}/cache.manifest" | ||
echo "[$(date)] Archiving diffs..." | ||
mkdir -p "${CACHE_FOLDER}" | ||
tar -cf "${CACHE_FOLDER}/cache.tar" --totals --files-from "${SCRIPT_PATH}/cache.manifest" | ||
echo "[$(date)] Done! $(du -h "${CACHE_FOLDER}/cache.tar")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 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 | ||
|
||
ARG USERNAME=node | ||
COPY --chown=${USERNAME}:${USERNAME} . /repo-source-tmp/ | ||
RUN mkdir /usr/local/etc/devcontainer-cache \ | ||
&& chown ${USERNAME} /usr/local/etc/devcontainer-cache /repo-source-tmp \ | ||
&& su ${USERNAME} -c "\ | ||
cd /repo-source-tmp \ | ||
&& .devcontainer/cache/before-cache.sh \ | ||
&& .devcontainer/prepare.sh \ | ||
&& .devcontainer/cache/cache-diff.sh" \ | ||
&& rm -rf /repo-source-tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/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 | ||
# in GitHub Codespaces occurs parallel to other startup activities and does not | ||
# really add to the overal startup time given how quick the operation ends up being. | ||
|
||
set -e | ||
|
||
SOURCE_FOLDER="$(cd "${1:-"."}" && pwd)" | ||
CACHE_FOLDER="${2:-"/usr/local/etc/devcontainer-cache"}" | ||
|
||
if [ ! -d "${CACHE_FOLDER}" ]; then | ||
echo "No cache folder found." | ||
exit 0 | ||
fi | ||
|
||
echo "[$(date)] Expanding $(du -h "${CACHE_FOLDER}/cache.tar") file to ${SOURCE_FOLDER}..." | ||
cd "${SOURCE_FOLDER}" | ||
tar -xf "${CACHE_FOLDER}/cache.tar" | ||
rm -f "${CACHE_FOLDER}/cache.tar" | ||
echo "[$(date)] Done!" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/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 | ||
# to create an image that speeds up first time use of the dev container by "caching" the results | ||
# of these commands. Developers can still run these commands without an issue once the container is | ||
# up, but only differences will be processed which also speeds up the first time these operations occur. | ||
|
||
yarn install | ||
yarn electron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: VS Code Repo Dev Container Cache Image Generation | ||
|
||
on: | ||
push: | ||
# Currently doing this for master, but could be done for PRs as well | ||
branch: | ||
- 'master' | ||
|
||
# Only updates to these files result in changes to installed packages, so skip otherwise | ||
paths: | ||
- '**/package.json' | ||
- '**/package-lock.json' | ||
- '**/yarn.lock' | ||
|
||
jobs: | ||
devcontainer: | ||
name: Generate cache image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Azure CLI login | ||
id: az_login | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZ_ACR_CREDS }} | ||
|
||
- name: Build and push | ||
id: build_and_push | ||
run: | | ||
set -e | ||
ACR_REGISTRY_NAME=$(echo ${{ secrets.CONTAINER_IMAGE_REGISTRY }} | grep -oP '(.+)(?=\.azurecr\.io)') | ||
az acr login --name $ACR_REGISTRY_NAME | ||
GIT_BRANCH=$(echo "${{ github.ref }}" | grep -oP 'refs/(heads|tags)/\K(.+)') | ||
if [ "$GIT_BRANCH" == "" ]; then GIT_BRANCH=master; fi | ||
.devcontainer/cache/build-cache-image.sh "${{ secrets.CONTAINER_IMAGE_REGISTRY }}/public/vscode/devcontainers/repos/microsoft/vscode" "master" | ||