Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement waitFor in .devcontainer.json #1342

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bkneis
Copy link
Contributor

@bkneis bkneis commented Oct 30, 2024

Using the reference implementation I have implemented the waitFor enum defined by devcontainer.json, alongside the --skip-non-blocking-commands flag. The waitFor attribute actually does nothing without this flag, when combined, it allows a developer to skip life cycle hooks. I have tested locally by using devpod and devcontainer cli to run a .devcontainer.

➜  devpod git:(feature/wait-for) ✗ ./devpod-cli up --id hookstest1 ~/hooktest/ 
08:58:56 info Creating devcontainer...
08:58:56 info Running initializeCommand from devcontainer.json: 'sh -c echo ==================================== init'
08:58:56 info ==================================== init
08:58:56 info Inspecting image mcr.microsoft.com/devcontainers/python:1-3.12
08:58:57 info 5f79af92eaca15d84c29f6f269e0d3a5a2b13fdca8daa5d2cd7ea7aac42e4924
08:58:57 info Setup container...
08:58:58 info Chown workspace...
08:58:58 info Chown projects...
08:58:58 info Run command : echo ==================================== create...
08:58:58 info ==================================== create
08:58:58 done Successfully ran command : echo ==================================== create
08:58:58 info Run command : echo ==================================== content...
08:58:58 info ==================================== content
08:58:58 done Successfully ran command : echo ==================================== content
08:58:58 info Run command : echo ==================================== postcreate...
08:58:58 info ==================================== postcreate
08:58:58 done Successfully ran command : echo ==================================== postcreate
08:58:58 info Run command : echo ==================================== start...
08:58:58 info ==================================== start
08:58:58 done Successfully ran command : echo ==================================== start
08:58:58 info Run command : echo ==================================== attach...
08:58:58 info ==================================== attach
08:58:58 done Successfully ran command : echo ==================================== attach
08:58:58 info Download PyCharm from https://download.jetbrains.com/product?code=PY&platform=linux
08:58:58 info Extract PyCharm...
➜  devpod git:(feature/wait-for) ✗ ./devpod-cli up --id hookstest2 --skip-non-blocking-commands ~/hooktest/
08:59:17 info Creating devcontainer...
08:59:17 info Running initializeCommand from devcontainer.json: 'sh -c echo ==================================== init'
08:59:17 info ==================================== init
08:59:17 info Inspecting image mcr.microsoft.com/devcontainers/python:1-3.12
08:59:17 info 2658ceb386b94dee170e75378f45c91c568cf3ab1c186042688642581a5af9ff
08:59:18 info Setup container...
08:59:18 info Chown workspace...
08:59:18 info Chown projects...
08:59:18 info Run command : echo ==================================== create...
08:59:18 info ==================================== create
08:59:18 done Successfully ran command : echo ==================================== create
08:59:18 info Run command : echo ==================================== content...
08:59:18 info ==================================== content
08:59:18 done Successfully ran command : echo ==================================== content
08:59:18 info waited for updateContentCommands to finish, completed lifecycle hooks
08:59:18 info Download PyCharm from https://download.jetbrains.com/product?code=PY&platform=linux
08:59:18 info Extract PyCharm...

In the example here, you can see that all hooks are ran. If I then specify --skip-non-blocking-commands, only up to updateContentCommand is ran since this is what I set waitFor to.

.devcontainer.json

{
	"name": "Python 3",
	"image": "mcr.microsoft.com/devcontainers/python:1-3.12",
	"customizations": {
		"vscode": {
			"settings": {},
			"extensions": [
				"streetsidesoftware.code-spell-checker"
			]
		}
	},
	"portsAttributes": {
		"9000": {
			"label": "Hello Remote World",
			"onAutoForward": "notify"
		}
	},

	"initializeCommand": "echo ==================================== init",
	"onCreateCommand": "echo ==================================== create",
	"updateContentCommand": "echo ==================================== content",
	"postStartCommand": "echo ==================================== start",
	"postAttachCommand": "echo ==================================== attach",
	"waitFor": "updateContentCommand",
	"postCreateCommand": "echo ==================================== postcreate"
}

Fixes #162

@bkneis bkneis marked this pull request as draft October 30, 2024 14:44
@bkneis bkneis marked this pull request as ready for review October 31, 2024 09:03
@bkneis bkneis requested review from pascalbreuninger and a team October 31, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support waitFor in lifecycle hooks
1 participant