Cypress + Docker + Apple Silicon / Arm - docker

I am trying to dockerize my tests and run them on M1 (Arm).
my Dockerfile looks like that:
FROM cypress/browsers:latest
WORKDIR /projectName
COPY package.json .
COPY tsconfig.json .
COPY cypress.config.ts .
COPY /cypress .
COPY makefile .
RUN npm install -g yarn
RUN yarn install
CMD tail -f /dev/null
I then use a Makefile with a few commands:
build_docker_arm:
sudo docker build ${ARM_PLATFORM} -t projectName .
start_docker_arm:
docker run ${ARM_PLATFORM} -d -t -i -v `pwd`/cypress:/fenrir/cypress -name=projectName projectName
run_docker_chrome:
docker exec -t -i projectName npx cypress run --browser chrome --spec "cypress/e2e/features/*"
When I run make run_docker_chrome I get this
If I try to run without the --browser chrome then the tests work

See open issue in cypress:
Add Arm browsers to linux/arm64 Docker images
https://github.com/cypress-io/cypress-docker-images/issues/695

Related

Copy file from dockerfile build to host - bandit

I just started learning docker. To teach myself, I managed to containerize bandit (a python code scanner) but I'm not able to see the output of the scan before the container destroys itself. How can I copy the output file from inside the container to the host, or otherwise save it?
Right now i'm just using bandit to scan itself basically :)
Dockerfile
FROM python:3-alpine
WORKDIR /
RUN pip install bandit
RUN apk update && apk upgrade
RUN apk add git
RUN git clone https://github.com/PyCQA/bandit.git ./code-to-scan
CMD [ "python -m bandit -r ./code-to-scan -o bandit.txt" ]
You can mount a volume on you host where you can share the output of bandit.
For example, you can run your container with:
docker run -v $(pwd)/output:/tmp/output -t your_awesome_container:latest
And you in your dockerfile:
...
CMD [ "python -m bandit -r ./code-to-scan -o /tmp/bandit.txt" ]
This way the bandit.txt file will be found in the output folder.
Better place the code in your image not in the root directory.
I did some adjustments to your Dockerfile.
FROM python:3-alpine
WORKDIR /usr/myapp
RUN pip install bandit
RUN apk update && apk upgrade
RUN apk add git
RUN git clone https://github.com/PyCQA/bandit.git .
CMD [ "bandit","-r",".","-o","bandit.txt" ]`
This clones git in your WORKDIR.
Note the CMD, it is an array, so just devide all commands and args as in the Dockerfile about.
I put the the Dockerfile in my D:\test directory (Windows).
docker build -t test .
docker run -v D:/test/:/usr/myapp test
It will generate you bandit.txt in the test folder.
After the code is execute the container exits, as there are nothing else to do.
you can also put --rm to remove the container once it finishs.
docker run --rm -v D:/test/:/usr/myapp test

How to use "colcon build" in a Dockerfile?

I am trying to create a docker image based on ubuntu:20.04 where I want to install ROS2, ignition gazebo and the ROS2-ign-bridge with a Dockerfile.
The installation of ROS2 and ign work without any issue but during the bridge installation I need to use colcon. Heres that part from the Dockerfile:
## install ROS2 ignition gazebo bridge
RUN export IGNITION_VERSION=edifice
RUN mkdir -p ros_ign_bridge_ws/src
RUN git clone https://github.com/osrf/ros_ign.git -b foxy ros_ign_bridge_ws/src
WORKDIR ros_ign_bridge_ws
RUN rosdep install -r --from-paths src -i -y --rosdistro foxy
RUN colcon build
RUN source ros_ign_bridge_ws/install/setup.bash
RUN echo "source ros_ign_bridge_ws/install/setup.bash" >> ~/.bashrc
It fails during the colcon build step when I use
docker build -f Dockerfiles/companion_base.Dockerfile -t companion_base .
, but when I run the image created up to that step
docker run -it c125a17c2f68 /bin/bash
and then execute colcon build inside the container it works without any issue.
So what is the difference between RUN colcon build and running colcon build inside the container ?
The issue was that when you source something in a previous docker build step, it isn't available in the next step. So what I needed to do was do the sourcing and building in the same step:
RUN /bin/bash -c "source /opt/ros/foxy/setup.bash; colcon build"

Docker cache-from not all layers being run if no files have changed

I've added a simple repo that recreates this issue: https://github.com/cgreening/docker-cache-problem
We have a very simple Dockerfile.
To speed up our builds we're using the --cache-from directive and using a previous build as a cache.
We're seeing some weird behaviour where if the files have not changed the lines after the COPY line are not being run.
RUN yarn && yarn build
Does not seem to get executed so when the application tries to start node_modules is missing.
FROM node
RUN mkdir /app
COPY . /app
WORKDIR /app
RUN yarn && yarn build
ENTRYPOINT ["yarn", "start"]
We're deploying to Kubernetes but I can pull the image locally and see that the files are missing:
# docker run -it --entrypoint /bin/bash gcr.io/XXXXX
root#3561a9cdab6e:/app# ls
DEVELOPING.md Dockerfile Makefile README.md admin-tools app.dev.yaml jest.config.js package.json src tailwind.config.js tools tsconfig.json tslint.json yarn.lock
root#3561a9cdab6e:/app#
Edit:
I've managed to recreate the problem outside of our build system.
Initial build:
DOCKER_BUILDKIT=1 docker build -t gcr.io/XXX/test:a . --build-arg BUILDKIT_INLINE_CACHE=1
docker push gcr.io/XXX/test:a
All works - node_modules and build folder are there:
Clean up docker as if we starting from scratch like on the build system
docker system prune -a
Do another build:
DOCKER_BUILDKIT=1 docker build -t gcr.io/XXX/test:b . --cache-from gcr.io/XXX/test:a --build-arg BUILDKIT_INLINE_CACHE=1
docker push gcr.io/XXX/test:a
Everything is still fine.
Clean up docker as if we starting from scratch like on the build system
docker system prune -a
Do a third build:
DOCKER_BUILDKIT=1 docker build -t gcr.io/XXX/test:c . --cache-from gcr.io/XXX/test:b --build-arg BUILDKIT_INLINE_CACHE=1
Files are missing!
docker run -it --entrypoint /bin/bash gcr.io/topo-wme-dev-d725ec6e/test:c
root#d07f6f1d3b12:/app# ls
DEVELOPING.md Dockerfile Makefile README.md admin-tools app.dev.yaml coverage jest.config.js package.json src tailwind.config.js tools tsconfig.json tslint.json yarn.lock
No node_modules or build folder.

Docker build Share data with host

I hava a custom Dockerfile that setup and builds a project of mine.
But now I haven't beeing able to place that into a folder of the host. Here the script and docker file...
Command
sudo docker build --output type=local,dest=./build/server/server -f ./build/scripts/Dockerfile.server ./server
Dockerfile
FROM node:14 AS build-stage
WORKDIR /usr/src/project
RUN npm i nexe#3.3.7 -g
COPY package*.json ./
RUN npm install --only=production
COPY . .
RUN nexe server.js -t linux-x64-12.14.1
FROM scratch AS export-stage
COPY --from=build-stage /usr/src/project/server /
The docker buildkit needs to be enabled before running the build command:
export DOCKER_BUILDKIT=1
You are setting up the context wrong. The command should be:
sudo docker build --output type=local,dest=./build/server/server -f ./build/scripts/Dockerfile.server .
The dot at the end sets the build context to current directory structure.

kaniko docker build: can't find command

Newbie to kaniko, and try to build docker images in ubuntu docker host.
I have a local Dockerfile and main.go app
# Dockefile
FROM golang:1.10.3-alpine AS build
ADD . /src
RUN cd /src && go build -o app
FROM alpine
WORKDIR /app
COPY --from=build /src/app /app/
CMD [ "./app" ]
#main.go
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
And in command line, i run
docker run -it -v $(pwd):/usr \
gcr.io/kaniko-project/executor:latest \
--dockerfile=Dockerfile --context=/usr --no-push
Unfortunately, I got error like below
...
INFO[0006] Skipping paths under /proc, as it is a whitelisted directory
INFO[0006] Using files from context: [/usr]
INFO[0006] ADD . /src
INFO[0006] Taking snapshot of files...
INFO[0006] RUN cd /src && go build -o app
INFO[0006] cmd: /bin/sh
INFO[0006] args: [-c cd /src && go build -o app]
/bin/sh: go: not found
error building image: error building stage: waiting for process to exit: exit status 127
What's wrong? (docker version 18.09.0)
You need to use different path for context in kaniko. Your command to run this build should look like this:
docker run -it -v $(pwd):/context \
gcr.io/kaniko-project/executor:latest \
--dockerfile=Dockerfile --context=/context --no-push
In your command with /usr as context kaniko where overriding this path in all of Dockerfiles and in golang image, go is located in /usr path thats why it couldn't find it then
# which go
/usr/local/go/bin/go

Resources