How-to push/copy app folder contents in builder container

When building my golang app (https://github.com/Bas-ProRail/resin-datacollector-edge) with gradle there is an error, " ./gradlew: not found".

[datacollector] Step 1/6 : FROM resin/iot2000-golang:latest
[datacollector] —> 07d5f0804451
[datacollector] Step 2/6 : ENV INITSYSTEM on
[datacollector] Using cache
[datacollector] —> f9a3449b44ea
[datacollector] Step 3/6 : COPY . $GOPATH/src/github.com/streamsets
[datacollector] —> a0d18d65f287
[datacollector] Removing intermediate container 9cb7c4995b47
[datacollector] Step 4/6 : RUN cd $GOPATH/src/github.com/streamsets
[datacollector] —> Running in 5bf4700a4860
[datacollector] —> f4e869f2669c
[datacollector] Removing intermediate container 5bf4700a4860
[datacollector] Step 5/6 : RUN ./gradlew build
[datacollector] —> Running in 8552d193a253
[datacollector] /bin/sh: 1: ./gradlew: not found
[datacollector]
[datacollector] Removing intermediate container 8552d193a253
[datacollector] The command ‘/bin/sh -c ./gradlew build’ returned a non-zero code: 127

Is there a way to check if the COPY command did copy something in $GOPATH/src/github.com/streamsets? It should copy all contents of /resin-datacollector-edge/datacollector-edge in $GOPATH/src/github.com/streamsets.

Thank you for your help, Bas

Hello Bas,
sorry for the late reply. I had a look at the repo you linked and it seems like the Dockerfile you refer to has changed. Did you manage to solve the issue?

For testing purposes, you could add a RUN line after the command in question to display the contents of the folder:

COPY . $GOPATH/src/github.com/streamsets
RUN ls -la $GOPATH/src/github.com/streamsets

On the other hand, the actual issue is not that, but that you are breaking up your RUN command into two lines. The things to keep in mind:

  • WORKDIR sets where you are in the container by default (can be changed as many times as you want to
  • Every RUN starts at WORKDIR every time

Thus you RUN cd ..., but then the next RUN won’t be in that folder. In this case there are two ways to work around this:

FROM resin/iot2000-golang:latest
ENV INITSYSTEM on
WORKDIR  $GOPATH/src/github.com/streamsets
COPY . .
RUN ./gradlew build
....

and for example set WORKDIR later where it is more appropriate.

Or, you can run multiple commands in a single RUN, like this:

FROM resin/iot2000-golang:latest
ENV INITSYSTEM on
COPY . $GOPATH/src/github.com/streamsets
RUN cd $GOPATH/src/github.com/streamsets && \
      ./gradlew build
...

Here && says that if the command before that succeeds, the next one will commence. \ is just a line-break separator, that “the next line is still the same command, so continue”. Thus these two are eqivalent:

RUN command1 && \
    command2 && \
    command3 && \
    command4

and

RUN command1 && command2 && command3 && command4

See more info in the Dockerfile reference for the RUN command, COPY command, and WORKDIR command.

Let us know if this helps!

Thank you for assisting in this, with your commends I did a big cleanup on my dockerfile.template in

GitHub - Bas-ProRail/resin-datacollector-edge: Monitoring Siemens S7 PLCs /datacollector-edge/ app

my build with gradle is going great and with some altering in the streamsets.com package I end up with a successfull build and a unicorn!

Is there a way to reduce the size of the images the device has to download from the resin buildservers? Can I remove some unnecessary files before issuing the last CMD?

[Success]        Release successfully created!
[Info]           ┌───────────────┬────────────┬───────────────────────┐
[Info]           │ Service       │ Image Size │ Build Time            │
[Info]           ├───────────────┼────────────┼───────────────────────┤
[Info]           │ s7comm        │ 161.84 MB  │ < 1 second            │
[Info]           ├───────────────┼────────────┼───────────────────────┤
[Info]           │ datacollector │ 920.80 MB  │ 3 minutes, 12 seconds │
[Info]           └───────────────┴────────────┴───────────────────────┘
[Info]           Build finished in 4 minutes, 7 seconds

Great, we’re glad to hear that things are working :slight_smile:

You have a couple of options that you can use to reduce the download size. One is just like you said – you can remove any unnecessary files (just RUN rm <whatever> in your Dockerfile) at the end of your Dockerfile, before the CMD statement. That will shrink your image down some.

Another thing you can do is turn on the delta feature. This will cause your device to download only the changes between updates rather than the full image every time. The first download will still take the same amount of time/data, but future downloads will be far faster and smaller.

The best news is that you can use both of these together to help shrink your download time and size!