0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

快適なCode Editorの作り方

Last updated at Posted at 2025-12-19

はじめに

 業務でSageMaker StudioのCode Editorを利用していますが、正直使いにくい、と不満に感じましたので、快適なCode Editorの構築方法を整理してみました。

問題点

A. Bash補完がない
 普段、SAMやCloudFormation、AWS CLIの利用や、Git操作でキーボード操作をしますが、bash補完がないため、tabキーを押しても補完が効かなく、スムーズに進められない、と不満に感じることがあります。

B. ソースコードやミドルウェア、ライブラリが消えている
 Code Editorを初めて触ってみて、編集中のソースコードやインストールしたミドルウェア、ライブラリが次回起動したときに消えており、「あれっ!?」と困惑しましたが、これはSageMaker Studioのコンテナ設計によるもので、セッション終了時コンテナが破棄されるため、ファイル等が消失してしまいます。そのため、毎回インストールしなおすといった不便さがあります。

解決策

  1. EFSの利用
     ソースコード等のテキストデータの永続化に使用します。

  2. カスタムイメージ化
     ミドルウェアやライブラリのインストールやチーム内で同一の環境を提供する点を踏まえ、カスタムイメージ化を選択しました。

  3. Bash補完の設定
     Dockerfile内でBash補完のインストールを記述し、補完の設定はライフサイクル設定で対応しています。

 上記の内容を踏まえたカスタムイメージのDockerfileとライフサイクル設定が以下のようになります。

Code EditorをカスタマイズしたDockerfile
FROM public.ecr.aws/sagemaker/sagemaker-distribution:latest-gpu
ARG NB_USER="sagemaker-user"
ARG NB_UID=1000
ARG NB_GID=100
ENV MAMBA_USER=$NB_USER
ENV EXTENSION_LOC=/opt/amazon/sagemaker/sagemaker-code-editor-server-data/extensions

USER root

# Install scrapy in the base environment
RUN micromamba install -y --name base -c conda-forge scrapy

# Download VSCodeVim
RUN \
  wget https://github.com/VSCodeVim/Vim/releases/download/v1.27.2/vim-1.27.2.vsix \
  -P /tmp/exts/ --no-check-certificate

COPY requirements.txt /tmp/requirements.txt
COPY extensions.txt /tmp/extensions.txt

# Install python dependencies
WORKDIR /tmp
RUN \
  pip install --upgrade pip && \
  pip install -r requirements.txt

# Install the extensions
RUN while read ext; do \
    sagemaker-code-editor \
      --install-extension "${ext}" \
      --extensions-dir "${EXTENSION_LOC}"; \
  done < /tmp/extensions.txt

# Install bash completion
RUN apt-get install -y bash-completion

USER $MAMBA_USER
ENTRYPOINT ["entrypoint-code-editor"]
Bash補完を設定するライフサイクル設定
#!/bin/bash
set -e

echo 'if [ -f /etc/bash_completion ]; then . /etc/bash_completion; fi' >> ~/.bashrc
echo 'if command -v aws_completer > /dev/null 2>&1; then complete -C aws_completer aws; fi' >> ~/.bashrc
echo 'if [ -f /usr/share/bash-completion/completions/git ]; then . /usr/share/bash-completion/completions/git; fi' >> ~/.bashrc
source ~/.bashrc

さいごに

 これでまともな開発環境ができ、キーボード操作もスムーズなので最高です!
 また改良すべき点が出ましたら別の機会に書こうと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?