Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Add on_start label for running a command every time the container starts #219

Merged
merged 3 commits into from
Jul 1, 2019

Conversation

deansheather
Copy link
Member

Adding the on_open label to an image will cause sail to exec that command inside of the container's project directory every time it creates a container.

Added the new label to the documentation.

When this was discussed in #191, the concept was a .sail/on_open file rather than a label. This PR uses a label instead of a file, as (in my opinion) a label seems to be a more "sail way" of doing this. As using a label for this functionality hasn't been discussed, this PR should not be merged until this is discussed.

Emulating the .sail/on_open file is as simple as LABEL on_open ".sail/on_open", and making sure that .sail/on_open has a shebang and is executable.

Closes #191.

Adding the `on_open` label to an image will cause sail to exec that
command inside of the container's project directory every time it starts
a container.

Added the new label to the documentation.
@deansheather
Copy link
Member Author

Still need to write tests for this before this can be merged, but I'd like to hear any thoughts before doing so.

@deansheather
Copy link
Member Author

Maybe this label should be changed to on_start.

@nathanpotter
Copy link
Contributor

This looks good if you want to start working on tests for it.

I agree, I think we should name it on_start, seems to be a bit more clear.

Copy link
Member

@ammario ammario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_start definitely makes more sense

- Rename the on_open label to on_start
- Use docker cli directly to run on_start label rather than docker API
- Drop (*runner).runInContainer(...) in favour of internal/dockutil
- Drop expandDir(...) in favour of an existing function
@deansheather deansheather changed the title Add on_open label for running a command every time the container starts Add on_start label for running a command every time the container starts Jun 20, 2019
@deansheather deansheather marked this pull request as ready for review June 27, 2019 03:46
@deansheather
Copy link
Member Author

Is the only way to write tests for this to make a new GitHub repository with an on_start label?

@nathanpotter
Copy link
Contributor

To test it, you could add an example hat showing how to use the label, maybe just create a file in the container or something, then use that example hat in a test and validate that whatever changes the on_start command did actually occurred after the container is started

@deansheather
Copy link
Member Author

I'm having an issue running the tests on my machine if I run all of them at the same time. Almost every time a random Test_runner test will fail while trying to get the code-server port:

--- FAIL: Test_runner/BaseImageHat (29.99s)
    --- PASS: Test_runner/BaseImageHat/Labels (0.01s)
    --- PASS: Test_runner/BaseImageHat/CodeServerStarts (0.11s)
    --- FAIL: Test_runner/BaseImageHat/FromContainer (5.45s)
        require.go:794: 
                    Error Trace:    runner_test.go:68
                    Error:          Received unexpected error:
                                    failed to find code server port:
                                        go.coder.com/sail.runnerFromContainer
                                            /home/dean/git/github.com/cdr/sail/runner.go:495
                                      - failed while trying to find code-server port:
                                        go.coder.com/sail.codeServerPort
                                            /home/dean/git/github.com/cdr/sail/codeserver.go:184
                                      - failed to find port:
                                        go.coder.com/sail/internal/codeserver.init.ializers
                                            /home/dean/git/github.com/cdr/sail/internal/codeserver/proc.go:15
                    Test:           Test_runner/BaseImageHat/FromContainer

If I run tests with -test.parallel 1 it succeeds. Should we disable parallel testing for now?

@deansheather deansheather requested a review from ammario June 28, 2019 10:30
@ammario ammario removed their request for review June 28, 2019 16:51
@deansheather
Copy link
Member Author

@nathanpotter Could you please approve the tests?

@deansheather deansheather merged commit bcf9063 into master Jul 1, 2019
@deansheather deansheather deleted the on_open-label branch July 1, 2019 22:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

post build initialization
3 participants