question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CI] Discussion about Docker and CI

See original GitHub issue

I open this issue to talk about CI Goal is to optimize/improve the way we build docker images.

I’ve already tested a lot before open this issue.

Today a full build take 1H image

Why is this so long ?

  • Repeated build of the same dependencies ( OZW )
  • Installation of the same npm packages again and again
  • Our dockerfile is not cache efficient

Layers caching

First problem I encountered is circleci. For using layers caching we must pay for it ( I don’t really understand why to be honest ). Fir that reason, all tests and implementation will be done on Github Workflows.

Dependencies

Open Zwave

To avoid building openzwave from source there is some simple solution => Multi Stage build

We take compiled binary from an already builded openzwave image. We are lucky because openzwave build their own and we can get real version tag ( not commit like today )

So OZW can now be added in your image like this:

# OpenZwave version 1.6.1520 
FROM chrisns/openzwave:alpine-1.6.1520 as ozw

# Just copy conf and binaries
COPY --from=ozw /usr/local/include/openzwave /usr/local/include/openzwave
COPY --from=ozw /openzwave/libopenzwave.so* /lib/
COPY --from=ozw /openzwave/config /usr/local/etc/openzwave

And voilà , OZW in our images without building it ( Several minutes saved here 😃 )

node_modules

Also named by me “the tricky part” ( a lot of fail 😅 )

Even in active project like Gladys, npm deps doesn’t change so much, why node_modules is not cached by docker when building ?

Simple answer, because we run npm install on the whole base code ! Cache is invalidated on each build.

Simple solution is to copy only package.json and lock file and run npm install on it, that way cache will work if no modification is commited , cache will be used by docker

After implementation, I’m able to build docker images in only 5 minutes ( for all platforms ) with change in codebase ( server and/or front )

image


There is some work to do but I need feedback from @GladysAssistant/core to know if I continue on this way or not.

PS: DockerFile for testing => https://github.com/VonOx/GLADYS_CI/blob/master/docker/Dockerfile.buildx STEP 2 is not easy to maintain I know that 😉 .

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
VonOxcommented, Jan 11, 2021

Yes this is tricky because in Gladys each service have their own package.

But I found a solution 😃

Full build with test and no cache take 1H15 Cached build + test take 17 minutes

image

Docker stage ( only building image ) 2 minutes, I can’t do better

image

Now I need to test generated images. PR incomming

0reactions
Pierre-Gillescommented, Jan 19, 2021

Got it, nice!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker and CI/CD tutorial: a deep dive into containers | CircleCI
Docker is a platform for developers and sysadmins to develop, deploy, and run applications using containers. Docker is also referred to as an ......
Read more >
Continuous integration with Docker
Continuous Integration (CI) is the part of the development process where you're looking to get your code changes merged with the main branch...
Read more >
Role of Docker in CI/CD Pipeline - LinkedIn
The main focus of the CI/CD pipeline is to deliver and integrate changes continuously. First, you must create a workflow and run it...
Read more >
Run your CI/CD jobs in Docker containers - GitLab Docs
To run CI/CD jobs in a Docker container, you need to: Register a runner so that all jobs run in Docker containers. Do...
Read more >
CI CD Docker - How to create a CI CD Pipeline with Amazon ...
A CI CD Pipeline or Continuous Integration Continuous Delivery Pipeline is a set of instructions to automate the process of Software tests, builds,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found