Wednesday, December 4, 2019

jenkins-log.txt Permission denied

I started getting the error below, after recreating Jenkins setup thru helm charts. At the beginning I thought I had missed to install a plugin, or installed one that corrupted Jenkins pipelines. So after starting from scratch I could not find why it was working before and then got broken.

sh: 1: cannot create /home/jenkins/agent/workspace/myproject/durable-48fa5881/jenkins-log.txt: Permission denied

So after reading a thread on Jenkins blog; I realized that "Jenkins" user is being used by Jenkins, and I was using "myuser" in my pod. So, I changed everything in my Dockerfile to match Jenkins slave image, like the following:

RUN groupadd --gid 10000 jenkins && useradd --gid 10000 --uid 10000 jenkins --shell /bin/bash
RUN mkdir /home/jenkins && chown -R jenkins:jenkins /home/jenkins
USER jenkins
WORKDIR /home/jenkins

After that, the permission denied error went away. I am still wondering how this was working before...


Tuesday, June 25, 2019

sbt-native-packager /opt/docker permission denied

I was getting all sorts of issues when trying to create files or directories below "/opt/docker" path. I tried adding:

import com.typesafe.sbt.packager.docker.DockerChmodType
dockerChmodType := DockerChmodType.UserGroupWriteExecute

It did not work, I was still getting errors, permission denied, while trying to write PID file to "/opt/docker/PID_FILE".

The solution is adding the following:

javaOptions in Universal ++= Seq(
  // Since play uses separate pidfile we have to provide it with a proper path  // name of the pid file must be play.pid  s"-Dpidfile.path=/var/run/play.pid")

Basically indicating Play framework to write PID file in another location, then:

dockerCommands ++= Seq(
  ExecCmd("RUN", "mkdir", "-p", s"/var/run/")
)

It would create another directory. Then, execute:

sbt dist && sbt docker:publishLocal

Finally you can write the following in a bash file:

dir=$(pwd)
docker run -v $dir/my_play_project:/var/run -v \ 
$dir/my_play_project/logs:/opt/docker/logs -p 9000:9000 \ 
 my_play_project:1.0