Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-P ubuntu-latest=node:22-bookworm
--container-options=--memory=32g --network=host
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Exclude large directories that aren't needed for build
vscode/node_modules

# Exclude build artifacts
*.tar.gz
*.log

# Exclude development files
.vscode/
.idea/
*.swp
*.swo
*~

# Exclude OS files
.DS_Store
Thumbs.db
25 changes: 16 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
# The main job for building the application
build:
name: Build sagemaker-code-editor
runs-on: ubuntu-latest
Expand Down Expand Up @@ -37,7 +38,13 @@ jobs:
- name: Apply patches (if any)
run: |
if [ -d patches ] && [ "$(ls -A patches)" ]; then
quilt push -a || true
{
quilt push -a --leave-rejects --color=auto
} || {
printf "\nPatching error, review logs!\n"
find ./vscode -name "*.rej"
exit 1
}
fi

- name: Set Development Version
Expand All @@ -53,18 +60,17 @@ jobs:
cd vscode
export DISABLE_V8_COMPILE_CACHE=1
export UV_THREADPOOL_SIZE=4

npm install -g node-gyp

# Install dependencies using npm, skip optional and native modules
npm install

VSCODE_RIPGREP_VERSION=$(jq -r '.dependencies."@vscode/ripgrep"' package.json)
mv package.json package.json.orig
jq 'del(.dependencies."@vscode/ripgrep")' package.json.orig > package.json

npm install
npm install --ignore-scripts "@vscode/ripgrep@${VSCODE_RIPGREP_VERSION}"

# Run the gulp build task with memory optimizations
ARCH_ALIAS=linux-x64
npx gulp vscode-reh-web-${ARCH_ALIAS}-min
node --max-old-space-size=32768 --optimize-for-size \
./node_modules/gulp/bin/gulp.js \
"vscode-reh-web-${ARCH_ALIAS}-min"

- name: Find build output
id: find_output
Expand Down Expand Up @@ -96,6 +102,7 @@ jobs:
tar czf $TARBALL -C "$PARENT_DIR" "$BUILD_DIR_NAME"

- name: Upload build artifact
if: env.ACT == ''
uses: actions/upload-artifact@v4
with:
name: npm-package
Expand Down
21 changes: 9 additions & 12 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ jobs:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Checkout repo with submodules
uses: actions/checkout@v4
with:
node-version: 20
cache: npm
- run: npm ci
- name: Download build artifact
if: github.event_name != 'pull_request'
uses: actions/download-artifact@v4
submodules: recursive
- name: Set up Node.js
uses: actions/setup-node@v4
with:
name: build-package
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
node-version: 20
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Run E2E tests
run: |
# Add your actual E2E test commands here
echo "Running E2E tests..."
echo "[PLACEHOLDER] Running E2E tests..."
# Example: npm run test:e2e
- uses: actions/upload-artifact@v4
if: failure()
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
.pc
.pc
.artifacts
bin
82 changes: 82 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.PHONY: build-cache build install-act run-github run-local clean-vscode clean

build-cache:
@echo "Building SageMaker Code Editor (multi-stage npm cache)..."
docker buildx build \
--platform linux/amd64 \
--progress=plain \
--memory=32g \
-t npm-cache:latest \
-f scripts/Dockerfile.build.cache .

build:
@echo "Building SageMaker Code Editor (original)..."
docker buildx build \
--platform linux/amd64 \
--progress=plain \
--memory=32g \
--output type=local,dest=./.artifacts \
-t localbuild:latest \
-f scripts/Dockerfile.build .

install-act:
@echo "Installing act (GitHub Actions runner)..."
@if ! command -v act >/dev/null 2>&1 && [ ! -f ./bin/act ]; then \
curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | bash; \
echo "act installed successfully"; \
else \
echo "act is already available"; \
fi

run-github: install-act
@echo "Running complete GitHub Actions workflow locally..."
@echo "Available workflows:"
@ls -la .github/workflows/
@echo ""
@echo "Running full build.yml workflow..."
@if command -v act >/dev/null 2>&1; then \
act push -W .github/workflows/build.yml --platform ubuntu-22.04=catthehacker/ubuntu:act-22.04 --container-options "--memory=32g --memory-swap=32g"; \
else \
./bin/act push -W .github/workflows/build.yml --platform ubuntu-22.04=catthehacker/ubuntu:act-22.04 --container-options "--memory=32g --memory-swap=32g"; \
fi

run-local:
@if [ -z "$(TARBALL)" ]; then \
echo "Building and running SageMaker Code Editor locally on port 8888..."; \
docker build -f scripts/Dockerfile.dev -t local-code-editor-dev . || exit 1; \
echo "Stopping container..."; \
docker stop local-code-editor-dev; \
sleep 2; \
echo "Starting container on http://localhost:8888"; \
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; \
docker logs -f local-code-editor-dev; \
else \
echo "Building and running SageMaker Code Editor locally on port 8888..."; \
docker build -f scripts/Dockerfile.run --build-arg TARBALL=$(TARBALL) -t local-code-editor . || exit 1; \
echo "Stopping container..."; \
docker stop local-code-editor; \
sleep 2; \
echo "Starting container on http://localhost:8888"; \
docker run --rm -d -p 8888:8000 --name local-code-editor local-code-editor || exit 1; \
docker logs -f local-code-editor; \
fi

clean-vscode:
@echo "Cleaning VSCode node_modules..."
@find . -type d -name "node_modules" -exec rm -rf {} + 2>/dev/null || true
@rm -rf vscode/out/* 2>/dev/null || true
@echo "VSCode cleanup completed"

clean: clean-vscode
@echo "Cleaning act temporary files and Docker images..."
@echo "Removing act cache..."
@rm -rf ~/.cache/act 2>/dev/null || true
@echo "Act cleanup completed"

reset-vscode:
@echo "Resetting vscode submodule..."
git submodule update --init --recursive
git submodule foreach --recursive "git reset --hard HEAD && sudo git clean -fd"
@echo "Resetting patches..."
sudo rm -rf .pc/*

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ This script will:
- Run `yarn watch` from within the `vscode` folder
- Open a new terminal and run `./vscode/scripts/code-server.sh --launch`

## Make Commands

Available make targets for building and testing:

### 1. When making local changes to iterate faster where tarball generation is not required [each run takes 10-20 mins]
- `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
- `make clean-vscode` - Cleans node_modules and out files

### 2. Once local changes are tested; follow this process to generate minified tarball [each run takes ~40 mins to build]
- `make build-cache` - Build SageMaker Code Editor with multi-stage npm cache; Run once and layer gets cached with node_modules
- `make build` - Build SageMaker Code Editor and output artifacts (tarball) to ./artifacts
- `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`

### 3. This process is used to test and simulate github workflows locally [each run takes ~60 mins]
- `make run-github` - Run complete GitHub Actions workflow locally using act

### 4. Cleanup
- `make clean` - Cleans node_modules, out files, and act temporary files

## Troubleshooting and Feedback

For any issues that customers would like to report, please route to the `amazon-sagemaker-feedback` repository: https://github.com/aws/amazon-sagemaker-feedback
Expand Down
27 changes: 27 additions & 0 deletions scripts/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM npm-cache:latest AS builder

WORKDIR /workspace

# Declare a build argument to control the minify flag
ARG ARGS

# Copy source files except vscode so new patches are picked up without cache busting
COPY patches ./patches
COPY resources ./resources
COPY .git ./.git
COPY scripts/ ./scripts/
COPY .pc ./.pc
COPY LICENSE .
COPY LICENSE-THIRD-PARTY .

# Apply patches and build
RUN chmod +x scripts/docker-install.sh && \
./scripts/docker-install.sh -t "$(cat vscode/package.json | grep '"version"' | cut -d'"' -f4)"

RUN echo "Build arguments: $ARGS"
RUN chmod +x scripts/create-code-editor-tarball.sh && \
./scripts/create-code-editor-tarball.sh -v "$(cat vscode/package.json | grep '"version"' | cut -d'"' -f4)"

# Final stage: Minimal image with only the build artifacts to copy from
FROM scratch
COPY --from=builder /workspace/artifacts .
43 changes: 43 additions & 0 deletions scripts/Dockerfile.build.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM ubuntu:24.04 AS base-image

# Install required tools and Node.js
RUN apt-get update && apt-get install -y \
git \
python3 \
python3-pip \
build-essential \
curl \
quilt \
pkg-config \
libx11-dev \
libxkbfile-dev \
libsecret-1-dev \
libkrb5-dev \
libgssapi-krb5-2 \
time \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 22 (latest LTS)
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y nodejs

# Stage 2: NPM Dependencies Cache
# This stage uses the pre-configured base-image to build the cache.
FROM base-image AS npm-cache

WORKDIR /workspace

COPY vscode ./vscode
COPY patches ./patches
COPY resources ./resources
COPY .git ./.git
COPY scripts/postinstall.sh ./scripts/postinstall.sh
COPY scripts/docker-install.sh ./scripts/docker-install.sh
COPY scripts/copy-resources.sh ./scripts/copy-resources.sh
COPY .pc ./.pc
COPY LICENSE .
COPY LICENSE-THIRD-PARTY .

# Apply patches and build
RUN chmod +x scripts/docker-install.sh && \
./scripts/docker-install.sh -t "$(cat vscode/package.json | grep '"version"' | cut -d'"' -f4)"
36 changes: 36 additions & 0 deletions scripts/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM ubuntu:24.04 AS base-image

# Install required tools and Node.js
RUN apt-get update && apt-get install -y \
git \
python3 \
python3-pip \
build-essential \
curl \
quilt \
pkg-config \
libx11-dev \
libxkbfile-dev \
libsecret-1-dev \
libkrb5-dev \
libgssapi-krb5-2 \
time \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 22 (latest LTS)
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y nodejs

# Stage 2: NPM Dependencies Cache
# This stage uses the pre-configured base-image to build the cache.
FROM base-image AS npm-cache

# Install supervisord
RUN apt-get update && \
apt-get install -y supervisor

WORKDIR /workspace

EXPOSE 8080

# Following is the entrypoint script for local runs: /workspace/scripts/run-code-editor-dev.sh
24 changes: 24 additions & 0 deletions scripts/Dockerfile.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM public.ecr.aws/sagemaker/sagemaker-distribution:latest-cpu

# Accept tarball name as build argument
ARG TARBALL=code-editor1.8.0b5.tar.gz

# Switch to root to install
USER root

# Copy and extract the code editor to /tmp
COPY .artifacts/${TARBALL} /tmp/
RUN cd /tmp && tar -xzf ${TARBALL}

# Move to final location and set permissions
RUN mv /tmp/sagemaker-code-editor /opt/ && \
chmod +x /opt/sagemaker-code-editor/bin/code-server-oss

# Add to PATH
ENV PATH="/opt/sagemaker-code-editor/bin:$PATH"

# Expose port
EXPOSE 8000

# Run code-server-oss with host binding to all interfaces
CMD ["code-server-oss", "--host", "0.0.0.0", "--without-connection-token"]
Loading