GoogleCloudPlatform / GoogleCloudPlatform/training-data-analyst
ak8s course's CloudBuild test fails for the wrong reason
- Dominant language
- Jupyter Notebook
- Stars
- 8.6k
- Forks
- 6.1k
- Avg merge
- 4h 44m
- Merged PRs (30d)
- 2
Description
I was checking out the `courses/ak8s/v1.1/Cloud_Build/b/` Dockerfile as part of the MLOps intro course, and run into an issue, that seems to be due to problems with the code here.
The idea in that folder is:
* build a container with CloudBuild
* add an extra step that fails, so that way we simulate a failing test
So far so good, the code in there as but fails, but not the way it is supposed to, by the look of it.
* The way it supposed to fail, is that the `quickstart.sh` file should exit with exit code 1.
https://github.com/GoogleCloudPlatform/training-data-analyst/blob/490dad83ed991062b0da77927162c3dccd925631/courses/ak8s/v1.1/Cloud_Build/b/quickstart.sh#L2-L8
* The way it actually fails, is due to the `fail` argument passed in (and it replacing the command run in the container, and it not being found
https://github.com/GoogleCloudPlatform/training-data-analyst/blob/490dad83ed991062b0da77927162c3dccd925631/courses/ak8s/v1.1/Cloud_Build/b/cloudbuild.yaml#L4-L5
resulting in
```
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "fail": executable file not found in $PATH: unknown.
```
This can be easily tested by
```shell
$ chmod +x quickstart.sh
$ docker build -t quickstart .
$ docker run --rm quickstart fail
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "fail": executable file not found in $PATH: unknown.
```
What really needed for this pattern to work is replacing `CMD` with `ENTRYPOINT` in the relevant `Dockerfile`:
https://github.com/GoogleCloudPlatform/training-data-analyst/blob/490dad83ed991062b0da77927162c3dccd925631/courses/ak8s/v1.1/Cloud_Build/b/Dockerfile#L3
becoming
```
ENTRYPOINT ["/quickstart.sh"]
```
With that change, it truly behaves as required:
```
$ docker build -t quickstart .
[snip]
$ docker run --rm quickstart
Hello, world! The time is Tue Mar 30 15:44:47 UTC 2021.
$ docker run --rm quickstart fail
$ echo $?
1
```
Is it like this, or am I missing anything?
It is easily to see when having an updated `quickstart.sh` with something like
```
#!/bin/sh
if [ -z "$1" ]
then
echo "Hello, world! The time is $(date)."
exit 0
else
if [ "$1" == "success" ]; then
exit 0;
else
exit 1;
fi
fi
```
would make it visible, as then with the `ENTRYPOINT` change in the `Dockerfile` and these in `cloudbuild.yaml` this would fail:
```
- name: 'gcr.io/$PROJECT_ID/quickstart-image'
args: ['fail']
```
and this would succeed:
```
- name: 'gcr.io/$PROJECT_ID/quickstart-image'
args: ['succeed']
```
In the current setup (`CMD`), both of these would fail.
Contributor guide
Assessment
This issue has not been assessed yet.