Reputation: 3226
Currently I am trying to implement a contianer into my Github Actions workflow. However I am having difficulties figuring out how to run steps in the container itself.
The following workflow is used:
name: Laravel
on: pull_request
jobs:
laravel-checks:
runs-on: ubuntu-latest
container: thomasowow/laravel-php:7.4
steps:
- uses: actions/checkout@v2
- name: Yarn
run: |
yarn
This workflow results in the following error:
/__w/_temp/c399fe7d-6cd2-4cdc-bb06-acc829cddbb8.sh: 1: /__w/_temp/c399fe7d-6cd2-4cdc-bb06-acc829cddbb8.sh: yarn: not found
##[error]Process completed with exit code 127
It is unable to find yarn
. The thomasowow/laravel-php:7.4
runs locally with yarn
available. I have tested this with other things that should be avilable in the docker image and they were not found either. It looks like the steps are not being executed in the container.
The documentation states the following for the jobs.<job_id>.container
syntax:
A container to run any steps in a job that don't already specify a container
I know there are solutions that work without using a container, I would prefer to use it.
Anybody had the same issue or knows what I am doing wrong?
@DannyB pointed out that my image contains the following entrypoint:
["/bin/bash", "--login", "-c", "tail -f /dev/null"]
This might have been the cause of Github not being able to run things in the container properly.
They were required in the image to install nvm, node and yarn
SHELL ["/bin/bash", "--login", "-c"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
RUN nvm install 12.18.3
RUN npm install -g yarn
CMD ["/bin/bash"]
Removing SHELL
to RUN npm ...
solved the issue and Github was able again to run things in the container properly.
Currently I am still unable to install yarn without my old solution, but I think there are other ways to do this. Anybody suggestions how to do this in a clean way?
I was able to get node
and yarn
installed using this answer.
ENV NODE_VERSION=12.18.3
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN npm install -g yarn
Some attempts were made to COPY
from the office Node docker images. With this solution I was able to get node
working. npm
and yarn
were also running but with errors.
COPY --from=node:12.18.3 /usr/local/bin/node /usr/bin/node
...
Upvotes: 6
Views: 17270
Reputation: 14776
The problem seems to be in your image, and not in your syntax of GitHub Actions.
It seems like your entrypoint is:
["/bin/bash", "--login", "-c", "tail -f /dev/null"]
This is not compatible with what GitHub Actions needs - since it cannot enter into your container at all with that entrypoint.
You will probably need to change your entrypoint to its standard /bin/sh
or /bin/bash
entrypoint. Make sure that you can bash into it locally before you expect GitHub Actions to be able to work on it.
$ docker run --rm -it thomasowow/laravel-php:7.4 bash
As a "container sandbox" proof of concept, you can try the below action, and see that it works as advertised.
name: Experiment
on: [push]
jobs:
debug:
runs-on: ubuntu-latest
container: { image: alpine }
steps:
- run: uname -a
- run: cat /etc/alpine-release
- run: touch /hello
- run: ls /
In addition, you might be able to instruct GitHub Actions to use a different entrypoint with something like this:
container:
image: thomasowow/laravel-php:7.4
options: "--entrypoint /bin/bash"
But, first, you need to make sure it is working locally, with something like this:
$ docker run --rm -it --entrypoint='' thomasowow/laravel-php:7.4 yarn
Adding to the answer, since you added to your question. Installing things inside a docker image should be straight forward for the most part, including things like node and yarn.
Although I am not a node user, I suspect that the problem lies in the fact that you are using nvm
. In other languages (python, ruby) these "version managers" are designed to run in an interactive shell, knowing the user's environment and boot scripts. Inside docker, you should not need any version manager - since you do not need more than one version.
Look for ways to install your dependencies "plain vanilla", and avoid version managers in Dockerfiles, and I am sure that your problems will either go away, or be reduced to simpler ones.
Upvotes: 5