Missing installed dependencies when docker image is used

Viewed 1443

Here is my Dockerfile

FROM node:10

RUN apt-get -qq update && apt-get -qq -y install bzip2

RUN yarn global add @bluebase/cli && bluebase plugins:add @bluebase/cli-expo && bluebase plugins:add @bluebase/cli-web
RUN bluebase plugins

When the docker file is built it installs all dependencies, and the last command RUN bluebase plugins outputs the list of plugins installed. But when this image is pushed and used in github actions, bluebase is available globally but no plugins are installed. What am I doing wrong?

Github Workflow

name: Development CI

on:
  push:
    # Sequence of patterns matched against refs/heads
    branches:
      - '*' # Push events on all branchs
      - '*/*'
      - '!master' # Exclude master
      - '!next' # Exclude next
      - '!alpha' # Exclude alpha
      - '!beta' # Exclude beta

jobs:
web-deploy:
    container: 
      image: hashimsohail/bluebase-image
    name: Deploy Web
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      - name: Check BlueBase
        run: bluebase #Outputs list of comamnds available with bluebase

      - name: Check BlueBase Plugins
        run: bluebase plugins #Outputs no plugins installed

2 Answers

This was a tricky problem! Here is the solution that worked for me. I'll try and explain why below.

jobs:
  web-deploy:
    container:
      image: hashimsohail/bluebase-image
    name: Deploy Web
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Check BlueBase
        run: bluebase
      - name: Check BlueBase Plugins
        run: HOME=/root bluebase plugins
      - name: Check web plugin
        run: HOME=/root bluebase web:build --help

Background

Firstly the Docker image. The command bluebase plugins:add seems to be very dependent on the $HOME environment variable. Your Docker image is built as the root user, so $HOME is /root. The bluebase plugins:add command installs plugin dependencies at $HOME/.cache/@bluebase so they end up at /root/.cache/@bluebase.

Now the jobs.<id>.container feature. When your container is run there is some rather complicated Docker networking and volume mounts that take place. One of those mounts is -v "/home/runner/work/_temp/_github_home":"/github/home". This mounts local files from the host, including a copy of your checked out repository, into the container. Then it changes $HOME to point to /github/home.

Problem

The reason bluebase plugins doesn't work is because it depends on $HOME pointing to /root but now GitHub Actions has changed it to /github/home.

Solutions

A solution I tried was to install the plugins at /github/home instead of /root in the Docker image.

FROM node:10

RUN apt-get -qq update && apt-get -qq -y install bzip2

RUN mkdir -p /github/home
ENV HOME /github/home

RUN yarn global add @bluebase/cli && bluebase plugins:add @bluebase/cli-expo && bluebase plugins:add @bluebase/cli-web
RUN bluebase plugins

The problem with this is that the volume mount that GitHub Actions creates overwrites the /github/home directory. So then I tried a few tricks like symlinks or moving the .cache/@bluebase directory around to avoid it being clobbered by the mount. None of those worked.

So the only solution seemed to be changing $HOME back to /root. This should NOT be done permanently in the workflow because GitHub Actions depends on HOME=/github/home to work correctly. So the solution is to set it temporarily for each command.

HOME=/root bluebase web:build --help

Takeaway

The main takeaway from this is that any tooling pre-built in a container that relies on $HOME pointing to a specific location may not work correctly when used in the jobs.<container_id>.container syntax.

I do not think the issue with the image, it's easy to confirm on local image and you will see the that the plugin is available in Docker image.

Just try to run

docker build -t plugintest .
#then run the image on local system to verify plugin
docker run -it --rm --entrypoint "/bin/sh" plugintest -c "bluebase plugins"

Seems like the issue with your YML config file.

      image: hashimsohail/bluebase-image
    name: Deploy Web
    runs-on: ubuntu-latest

This line runs-on: ubuntu-latest make does not sense, I think it should be runs-on:ashimsohail/bluebase-image.

Related