Chaining Dockerfiles - after FROM, running npm no longer works? - docker

I'm experimenting with docker. I have a simple dockerfile, which includes java and node.
https://github.com/Quafadas/scala-mill
https://github.com/Quafadas/scala-mill/blob/master/Dockerfile
It's published to dockerhub. Now, I'd like to build an application downstream
FROM quafadas/scala-mill:latest
RUN java -version
#This doesn't work :-(.
RUN npm --version
The command RUN npm --version works in the base image linked above, but apparently, not when I'm building on top of it using the FROM directive. Is anyone able to help me understand why?
/bin/sh: npm: command not found
15:15:19
The command '/bin/sh -c npm --version' returned a non-zero code: 127
enter code here
``

There seem to have been a few recent commits to the repo which has apparently fixed the issue! I was able to build and run the Dockerfile to get the npm version without any issues!
In case you need additional modules (such as npm) to be installed on a base image that doesn't provide it, use a multi-stage Dockerfile with different FROM commands to get your necessary dependencies onto a single Dockerfile and a docker image later. Reference.

Related

Azure Pipelines: GraalVM Docker image build best practice

I'm currently doing some research on how to use GraalVM in our project which by now contains an array of Micronaut apps.
I've followed this Micronaut article:
https://guides.micronaut.io/latest/micronaut-creating-first-graal-app-maven-kotlin.html
using Micronaut 3.5.2, JDK 17 and Kotlin.
Everything is working as expected on localhost (Ubuntu 20.04) when building the Docker image by using
mvn package -Dpackaging=docker-native and running the app using
docker run --publish 8080:8080 graal-test
Now I'm trying to figure out how to build GraalVM Docker images in Azure Pipelines without installing prerequisites for every build. There seems to be very little information about how to do this.
I'm able to run a successful build by adding these two script build steps. task.prependpath is in effect in next build step, hence two separate script steps.
- script: |
curl -Lo graalvm-archive.tar.gz https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java17-linux-amd64-22.1.0.tar.gz
tar -xzf graalvm-archive.tar.gz
echo '##vso[task.prependpath]$(System.DefaultWorkingDirectory)/graalvm-ce-java17-22.1.0/bin'
- script: |
gu install native-image
sudo apt-get install build-essential libz-dev zlib1g-dev
native-image --version
Docker image build step.
# Build Docker image
- task: Maven#3
displayName: 'Build Docker'
inputs:
goals: 'package'
options: '-Pgraalvm -Dpackaging=docker-native -Djib.to.image=$(yourImageNameVar):$(yourImageTagVar) -DskipTests=true -Dmaven.javadoc.skip=true --batch-mode'
javaHomeOption: 'JDKVersion'
The resulting image has approx. virtual size 30MiB in GCR, and app startup time is less than 40ms in GKE.
Closest so far is this
https://github.com/Azure/azure-sdk-for-java/issues/21735#issuecomment-867134666
The azure pipelines ubuntu 20.04 images recently added Graal CE
21.1.0: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#graalvm
Unfortunately, the embedded link is broken.
Any hints on how to do this, will be highly appreciated.
Side-note
We managed to build 1 out of 5 Micronaut apps tested so far with GraalVM. There seems to be some issues with Kotlin and GraalVM.
Here's the non-broken link:
https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#graalvm
I hope this helps. I did notice on the issue that the CI pipeline support for GraalVM is not yet in place, but the VMs themselves are available on the Ubuntu image.

How to pass dotnet tools in to a docker

On root I used :
dotnet tool install --global dotnet-sonarscanner --version 4.7.1to install sonarscanner
and it's working:
SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
WARNING: Please specify the command 'begin' or 'end' to indicate whether pre- or post-processing is required. These parameters will become mandatory in a later release.
Post-processing started.
But in a docker it isn't:
root#3bea636a6418:/# dotnet sonarscanner
bash: dotnet: command not found
I tried to pass it:
export PATH="$PATH:/root/.dotnet/tools"
but with no luck
ps. ...and everything because of sonarscanner could not find java on docker:
SonarScanner for MSBuild 5.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI…
Could not find ‘java’ executable in JAVA_HOME or PATH.
The SonarScanner did not complete successfully
14:43:39.402 Post-processing failed. Exit code: 1
Cleaning up file based variables
ERROR: Job failed: exit code 1```
Install all the dependencies for your dotnet tools to work, ldd command can help you with this, and make sure all software required can be found also, for example can be found on the PATH variable if required.
to help you use interactive bash on the docker container, and add to your dockerfile if this works.
docker exec -it (container) bash
docker images usually installs what is required only, so you add the tools only to run your software successfully.
- apt-get update
- apt-get install --yes openjdk-11-jre
solved problem
ps. it's not that obvious because in docker bash when I run java -version I get answer that java is already installed

How to build a jibri docker image from unstable build?

Jitsi recently release a build 5207 which supports streaming to any server. This build is currently unstable and docker-jitsi-meet uses stable-5142. Now I want to build jibri docker image using 5207 build. I don't know where to make the changes to build the jibri docker image using unstable build.
Please help.
I'm able to create a docker image from unstable build. Below are the steps.
First create a docker image for base using unstable build. Go to base directory and run make JITSI_RELEASE=unstable JITSI_REPO=myimage OR You can use export JITSI_RELEASE=unstable and export JITSI_REPO=myimage will result in myimage/base:latest. I followed second approach here.
Now we have to create base-java image from myimage/base. for this we have change ARG JITSI_REPO=jitsi to ARG JITSI_REPO=myimage in Dockerfile in base-java directory. Now run make command. It will create myimage/base-java:latest
Now got to jibri directory and change ARG JITSI_REPO=jitsi to ARG JITSI_REPO=myimage in Dockerfile and finally run make command.
NOTE
Start the jibri container and check the jibri version using command docker exec docker-jitsi-meet_jibri_1 dpkg -l | grep jibri
UPDATE
Simply run FORCE_REBUILD=1 JITSI_RELEASE=unstable JITSI_REPO=your_dockerhub_username make command from docker-jitsi-meet directory. No need to do anything else. You can control which image to build by editing this line. base and base-java images are mandatory hence don't remove them from file.

npm library fails to install in GitLab CI

My Docker image build has been failing to build lately and I've managed to trace down
where exactly it struggles.
When the runner is executing RUN npm install react-scripts#2.1.8 -g --silent --no-optional (from Dockerfile)
it fails and gives no error output to work with. Job log shows no clue as to why it failed.
I figured I could SSH into the CI server but GitLab doesn't support direct SSH access into CI server for debugging purposes.
My question is how can I debug this ? What steps I should take ? I don't deal every day with
bug where I get no error output.
What are the conditions in which GitLab runner may fail to install it ?
Note:
I ran it locally and no problem whatsoever hence it must be problem within the CI.
is the build of your image is ok in your computer ? You can also install a gitlab runner in your computer to test your gitlabci file
Try removing the --silent flag from the npm install command. I reckon you'll see a bit more then.
Timeout of the build runner was to blame in this particular case. As soon as I reorganized the code in build script npm library was successfully installed.

How to ask sbt to only fetch dependencies, without compiling?

Is there a way to only download the dependencies but do not compile source.
I am asking because I am trying to build a Docker build environment for my bigger project.
The Idear is that during docker build I clone the project, download all dependencies and then delete the code.
Then use docker run -v to mount the frequently changing code into the docker container and start compiling the project.
Currently I just compile the code during build and then compile it again on run. The problem ist that when a dependencie changes I have to build from scratch and that takes a long time.
Run sbt's update command. Dependencies will be resolved and retrieved.

Resources