Skip to content

Instantly share code, notes, and snippets.

@skysan87
Created November 1, 2021 12:36
Show Gist options
  • Save skysan87/79af092e86979160a2b3ddb20b2d62c5 to your computer and use it in GitHub Desktop.
Save skysan87/79af092e86979160a2b3ddb20b2d62c5 to your computer and use it in GitHub Desktop.
Salesforceの開発環境をVSCodeのdevContainerで作成する設定

前提知識

  • Saleforceの開発環境をDockerコンテナ上に構築する
  • VSCodeのRemote DevelopmentでDockerコンテナとリモート接続する

ゴール

  • Dockerコンテナ作成時に、SFDXプロジェクトのテンプレートを作成する
    • 開発モデルは組織開発モデルを使用

課題

  • 単純にコンテナ内でSFDXプロジェクトを作成すると、プロジェクトのフォルダがルートから1階層下にできてしまう
    • コンテナ起動時にSFDXの拡張機能が認識されないため、何度か開く必要があった
    • 解決策:プロジェクト作成コマンドで--outputdir ../とオプション指定する必要がある
  • DockerfileのENTRYPOINTが効かない(シェルスクリプトが実行されない)
    • 解決策:devcontainer.jsonのpostCreateCommandオプションを使用する

実行環境

  • OS: macOS 11.6
  • Docker Desktop for Mac: 4.1.1
    • Engine: 20.10.8
  • VSCode: 1.61.2
    • 拡張機能: Remote Development: 0.21.0

プロジェクト構成

.
|__ .devcontainer
    |-- devcontainer.json
    |__ Dockerfile

実行方法

  1. VSCodeで.devcontainerフォルダを含むフォルダを開く
  2. Remote-Container: Reopen in Container
{
"name": "Salesforce Project (Community)",
"dockerFile": "Dockerfile",
"postCreateCommand": "if [ ! -e 'sfdx-project.json' ]; then sfdx force:project:create -n $(basename `pwd`) --manifest --outputdir ../; fi",
"extensions": [
"salesforce.salesforcedx-vscode",
"redhat.vscode-xml",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
"settings": {
"salesforcedx-vscode-apex.java.home": "/usr/lib/jvm/java-11-openjdk-amd64"
}
}
FROM salesforce/salesforcedx:latest-rc-full
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment