简体   繁体   中英

Download a git repository in Dockerfile

I use docker.com to build automatically whenever I puch a commit to my GitHub repository. (see https://docs.docker.com/docker-hub/builds/ )

I would like to call luacheck on all files in the docker image and let it fail if there are warnings.

I added a Lua error on purpose and added these lines in my Dockerfile :

RUN useradd -d /gluon gluon
RUN cd /gluon
RUN git clone https://github.com/rubo77/gluon/ gluon
RUN cd gluon

USER gluon

VOLUME /gluon
WORKDIR /gluon

RUN git checkout docker 
RUN cp -a docs/site-example/ site
RUN luacheckrc .; if [ $? -gt 0 ]; then exit 1; fi

see: https://github.com/rubo77/gluon/commits/docker

But it fails

/bin/sh: 1: cd: can't cd to /gluon

even before the git repository

You have to create the directory for the gluon user first and give it write-rights with:

FROM ubuntu
RUN useradd -d /gluon gluon
RUN apt-get update && apt-get install -y git
RUN mkdir /gluon
RUN chown -R gluon:gluon /gluon
USER gluon
RUN cd /gluon
RUN git clone https://github.com/rubo77/gluon/ gluon
RUN cd gluon

VOLUME /gluon
WORKDIR /gluon
RUN git checkout docker
RUN cp -a docs/site-example/ site
RUN luacheck .; if [ $? -gt 0 ]; then exit 1; fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM