Skip to content

Commit 5d40034

Browse files
author
Arkaprava De
committed
Added local build support for local testing
- Added docker buildx support to generate local tarball - Added support to run github workflows locally - Added support to run code-editor locally - Updated README with instructions to build and test for different usecases
1 parent e1451a8 commit 5d40034

17 files changed

+485
-60
lines changed

.actrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-P ubuntu-latest=node:22-bookworm
2+
--container-options=--memory=32g --network=host

.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Exclude large directories that aren't needed for build
2+
vscode/node_modules
3+
4+
# Exclude build artifacts
5+
*.tar.gz
6+
*.log
7+
8+
# Exclude development files
9+
.vscode/
10+
.idea/
11+
*.swp
12+
*.swo
13+
*~
14+
15+
# Exclude OS files
16+
.DS_Store
17+
Thumbs.db

.github/workflows/build.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ concurrency:
99
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1010

1111
jobs:
12+
# The main job for building the application
1213
build:
1314
name: Build sagemaker-code-editor
1415
runs-on: ubuntu-latest
@@ -37,7 +38,13 @@ jobs:
3738
- name: Apply patches (if any)
3839
run: |
3940
if [ -d patches ] && [ "$(ls -A patches)" ]; then
40-
quilt push -a || true
41+
{
42+
quilt push -a --leave-rejects --color=auto
43+
} || {
44+
printf "\nPatching error, review logs!\n"
45+
find ./vscode -name "*.rej"
46+
exit 1
47+
}
4148
fi
4249
4350
- name: Set Development Version
@@ -53,18 +60,17 @@ jobs:
5360
cd vscode
5461
export DISABLE_V8_COMPILE_CACHE=1
5562
export UV_THREADPOOL_SIZE=4
63+
64+
npm install -g node-gyp
5665
66+
# Install dependencies using npm, skip optional and native modules
5767
npm install
5868
59-
VSCODE_RIPGREP_VERSION=$(jq -r '.dependencies."@vscode/ripgrep"' package.json)
60-
mv package.json package.json.orig
61-
jq 'del(.dependencies."@vscode/ripgrep")' package.json.orig > package.json
62-
63-
npm install
64-
npm install --ignore-scripts "@vscode/ripgrep@${VSCODE_RIPGREP_VERSION}"
65-
69+
# Run the gulp build task with memory optimizations
6670
ARCH_ALIAS=linux-x64
67-
npx gulp vscode-reh-web-${ARCH_ALIAS}-min
71+
node --max-old-space-size=32768 --optimize-for-size \
72+
./node_modules/gulp/bin/gulp.js \
73+
"vscode-reh-web-${ARCH_ALIAS}-min"
6874
6975
- name: Find build output
7076
id: find_output
@@ -96,6 +102,7 @@ jobs:
96102
tar czf $TARBALL -C "$PARENT_DIR" "$BUILD_DIR_NAME"
97103
98104
- name: Upload build artifact
105+
if: env.ACT == ''
99106
uses: actions/upload-artifact@v4
100107
with:
101108
name: npm-package

.github/workflows/e2e.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@ jobs:
1616
runs-on: ubuntu-latest
1717
if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'pull_request'
1818
steps:
19-
- uses: actions/checkout@v4
20-
- uses: actions/setup-node@v4
19+
- name: Checkout repo with submodules
20+
uses: actions/checkout@v4
2121
with:
22-
node-version: 20
23-
cache: npm
24-
- run: npm ci
25-
- name: Download build artifact
26-
if: github.event_name != 'pull_request'
27-
uses: actions/download-artifact@v4
22+
submodules: recursive
23+
- name: Set up Node.js
24+
uses: actions/setup-node@v4
2825
with:
29-
name: build-package
30-
github-token: ${{ secrets.GITHUB_TOKEN }}
31-
run-id: ${{ github.event.workflow_run.id }}
26+
node-version: 20
27+
cache: 'npm'
28+
cache-dependency-path: '**/package-lock.json'
3229
- name: Run E2E tests
3330
run: |
3431
# Add your actual E2E test commands here
35-
echo "Running E2E tests..."
32+
echo "[PLACEHOLDER] Running E2E tests..."
3633
# Example: npm run test:e2e
3734
- uses: actions/upload-artifact@v4
3835
if: failure()

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.DS_Store
2-
.pc
2+
.pc
3+
.artifacts
4+
bin

Makefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
.PHONY: build-cache build install-act run-github run-local clean-vscode clean
2+
3+
build-cache:
4+
@echo "Building SageMaker Code Editor (multi-stage npm cache)..."
5+
docker buildx build \
6+
--platform linux/amd64 \
7+
--progress=plain \
8+
--memory=32g \
9+
-t npm-cache:latest \
10+
-f scripts/Dockerfile.build.cache .
11+
12+
build:
13+
@echo "Building SageMaker Code Editor (original)..."
14+
docker buildx build \
15+
--platform linux/amd64 \
16+
--progress=plain \
17+
--memory=32g \
18+
--output type=local,dest=./.artifacts \
19+
-t localbuild:latest \
20+
-f scripts/Dockerfile.build .
21+
22+
install-act:
23+
@echo "Installing act (GitHub Actions runner)..."
24+
@if ! command -v act >/dev/null 2>&1 && [ ! -f ./bin/act ]; then \
25+
curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | bash; \
26+
echo "act installed successfully"; \
27+
else \
28+
echo "act is already available"; \
29+
fi
30+
31+
run-github: install-act
32+
@echo "Running complete GitHub Actions workflow locally..."
33+
@echo "Available workflows:"
34+
@ls -la .github/workflows/
35+
@echo ""
36+
@echo "Running full build.yml workflow..."
37+
@if command -v act >/dev/null 2>&1; then \
38+
act push -W .github/workflows/build.yml --platform ubuntu-22.04=catthehacker/ubuntu:act-22.04 --container-options "--memory=32g --memory-swap=32g"; \
39+
else \
40+
./bin/act push -W .github/workflows/build.yml --platform ubuntu-22.04=catthehacker/ubuntu:act-22.04 --container-options "--memory=32g --memory-swap=32g"; \
41+
fi
42+
43+
run-local:
44+
@if [ -z "$(TARBALL)" ]; then \
45+
echo "Building and running SageMaker Code Editor locally on port 8888..."; \
46+
docker build -f scripts/Dockerfile.dev -t local-code-editor-dev . || exit 1; \
47+
echo "Stopping container..."; \
48+
docker stop local-code-editor-dev; \
49+
sleep 2; \
50+
echo "Starting container on http://localhost:8888"; \
51+
docker run --rm -d -p 8888:8000 -v .:/workspace -u $(id -u):$(id -g) --entrypoint /workspace/scripts/run-code-editor-dev.sh --name local-code-editor-dev local-code-editor-dev || exit 1; \
52+
docker logs -f local-code-editor-dev; \
53+
else \
54+
echo "Building and running SageMaker Code Editor locally on port 8888..."; \
55+
docker build -f scripts/Dockerfile.run --build-arg TARBALL=$(TARBALL) -t local-code-editor . || exit 1; \
56+
echo "Stopping container..."; \
57+
docker stop local-code-editor; \
58+
sleep 2; \
59+
echo "Starting container on http://localhost:8888"; \
60+
docker run --rm -d -p 8888:8000 --name local-code-editor local-code-editor || exit 1; \
61+
docker logs -f local-code-editor; \
62+
fi
63+
64+
clean-vscode:
65+
@echo "Cleaning VSCode node_modules..."
66+
@find . -type d -name "node_modules" -exec rm -rf {} + 2>/dev/null || true
67+
@rm -rf vscode/out/* 2>/dev/null || true
68+
@echo "VSCode cleanup completed"
69+
70+
clean: clean-vscode
71+
@echo "Cleaning act temporary files and Docker images..."
72+
@echo "Removing act cache..."
73+
@rm -rf ~/.cache/act 2>/dev/null || true
74+
@echo "Act cleanup completed"
75+
76+
reset-vscode:
77+
@echo "Resetting vscode submodule..."
78+
git submodule update --init --recursive
79+
git submodule foreach --recursive "git reset --hard HEAD && sudo git clean -fd"
80+
@echo "Resetting patches..."
81+
sudo rm -rf .pc/*
82+

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ This script will:
2828
- Run `yarn watch` from within the `vscode` folder
2929
- Open a new terminal and run `./vscode/scripts/code-server.sh --launch`
3030

31+
## Make Commands
32+
33+
Available make targets for building and testing:
34+
35+
### 1. When making local changes to iterate faster where tarball generation is not required [each run takes 10-20 mins]
36+
- `make run-local` - Build and run SageMaker Code Editor locally from source and does not require a TARBALL; this process runs a watcher so changes are automatically picked from local workspace
37+
- `make clean-vscode` - Cleans node_modules and out files
38+
39+
### 2. Once local changes are tested; follow this process to generate minified tarball [each run takes ~40 mins to build]
40+
- `make build-cache` - Build SageMaker Code Editor with multi-stage npm cache; Run once and layer gets cached with node_modules
41+
- `make build` - Build SageMaker Code Editor and output artifacts (tarball) to ./artifacts
42+
- `make run-local TARBALL=<tarball-name>` - Build and run SageMaker Code Editor locally on port 8888 using specified tarball from previos step. Example: `make run-local TARBALL=sagemaker-code-editor-1.101.2.tar.gz`
43+
44+
### 3. This process is used to test and simulate github workflows locally [each run takes ~60 mins]
45+
- `make run-github` - Run complete GitHub Actions workflow locally using act
46+
47+
### 4. Cleanup
48+
- `make clean` - Cleans node_modules, out files, and act temporary files
49+
3150
## Troubleshooting and Feedback
3251

3352
For any issues that customers would like to report, please route to the `amazon-sagemaker-feedback` repository: https://github.com/aws/amazon-sagemaker-feedback

scripts/Dockerfile.build

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM npm-cache:latest AS builder
2+
3+
WORKDIR /workspace
4+
5+
# Declare a build argument to control the minify flag
6+
ARG ARGS
7+
8+
# Copy source files except vscode so new patches are picked up without cache busting
9+
COPY patches ./patches
10+
COPY resources ./resources
11+
COPY .git ./.git
12+
COPY scripts/ ./scripts/
13+
COPY .pc ./.pc
14+
COPY LICENSE .
15+
COPY LICENSE-THIRD-PARTY .
16+
17+
# Apply patches and build
18+
RUN chmod +x scripts/docker-install.sh && \
19+
./scripts/docker-install.sh -t "$(cat vscode/package.json | grep '"version"' | cut -d'"' -f4)"
20+
21+
RUN echo "Build arguments: $ARGS"
22+
RUN chmod +x scripts/create-code-editor-tarball.sh && \
23+
./scripts/create-code-editor-tarball.sh -v "$(cat vscode/package.json | grep '"version"' | cut -d'"' -f4)"
24+
25+
# Final stage: Minimal image with only the build artifacts to copy from
26+
FROM scratch
27+
COPY --from=builder /workspace/artifacts .

scripts/Dockerfile.build.cache

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM ubuntu:24.04 AS base-image
2+
3+
# Install required tools and Node.js
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
python3 \
7+
python3-pip \
8+
build-essential \
9+
curl \
10+
quilt \
11+
pkg-config \
12+
libx11-dev \
13+
libxkbfile-dev \
14+
libsecret-1-dev \
15+
libkrb5-dev \
16+
libgssapi-krb5-2 \
17+
time \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Install Node.js 22 (latest LTS)
21+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
22+
apt-get install -y nodejs
23+
24+
# Stage 2: NPM Dependencies Cache
25+
# This stage uses the pre-configured base-image to build the cache.
26+
FROM base-image AS npm-cache
27+
28+
WORKDIR /workspace
29+
30+
COPY vscode ./vscode
31+
COPY patches ./patches
32+
COPY resources ./resources
33+
COPY .git ./.git
34+
COPY scripts/postinstall.sh ./scripts/postinstall.sh
35+
COPY scripts/docker-install.sh ./scripts/docker-install.sh
36+
COPY scripts/copy-resources.sh ./scripts/copy-resources.sh
37+
COPY .pc ./.pc
38+
COPY LICENSE .
39+
COPY LICENSE-THIRD-PARTY .
40+
41+
# Apply patches and build
42+
RUN chmod +x scripts/docker-install.sh && \
43+
./scripts/docker-install.sh -t "$(cat vscode/package.json | grep '"version"' | cut -d'"' -f4)"

scripts/Dockerfile.dev

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM ubuntu:24.04 AS base-image
2+
3+
# Install required tools and Node.js
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
python3 \
7+
python3-pip \
8+
build-essential \
9+
curl \
10+
quilt \
11+
pkg-config \
12+
libx11-dev \
13+
libxkbfile-dev \
14+
libsecret-1-dev \
15+
libkrb5-dev \
16+
libgssapi-krb5-2 \
17+
time \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Install Node.js 22 (latest LTS)
21+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
22+
apt-get install -y nodejs
23+
24+
# Stage 2: NPM Dependencies Cache
25+
# This stage uses the pre-configured base-image to build the cache.
26+
FROM base-image AS npm-cache
27+
28+
# Install supervisord
29+
RUN apt-get update && \
30+
apt-get install -y supervisor
31+
32+
WORKDIR /workspace
33+
34+
EXPOSE 8080
35+
36+
# Following is the entrypoint script for local runs: /workspace/scripts/run-code-editor-dev.sh

0 commit comments

Comments
 (0)