Skip to content

Commit

Permalink
implemented groovy script to configure admin user creation using envi…
Browse files Browse the repository at this point in the history
…ronment variables passed to the vm
  • Loading branch information
amr-yassir committed Aug 21, 2024
1 parent fe9d810 commit 84a7992
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
19 changes: 9 additions & 10 deletions tfgrid3/jenkins/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ FROM ubuntu

RUN apt update
RUN apt -y install wget openssh-server
RUN apt -y install gnupg

RUN wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
RUN wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
RUN echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | tee /etc/apt/sources.list.d/jenkins.list > /dev/null

RUN echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null

RUN apt-get update
RUN apt -y install jenkins
RUN apt-get update && apt-get -y install jenkins default-jre

RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && chmod +x /sbin/zinit

COPY rootfs /

EXPOSE 8080
RUN mkdir -p /root/.jenkins/init.groovy.d
COPY /set-admin-user.groovy /root/.jenkins/init.groovy.d/set-admin-user.groovy

EXPOSE 9090

ENTRYPOINT [ "/sbin/zinit", "init" ]
11 changes: 0 additions & 11 deletions tfgrid3/jenkins/rootfs/etc/zinit/print-jenkins-password.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion tfgrid3/jenkins/rootfs/etc/zinit/start-jenkins.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exec: /usr/bin/jenkins
exec: /usr/bin/jenkins --httpPort=9090
17 changes: 17 additions & 0 deletions tfgrid3/jenkins/set-admin-user.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!groovy

import jenkins.model.*
import hudson.security.*

def instance = Jenkins.getInstance()

def adminUsername = System.getenv("JENKINS_ADMIN_USERNAME") ?: "admin"
def adminPassword = System.getenv("JENKINS_ADMIN_PASSWORD") ?: "admin"

def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount(adminUsername, adminPassword)
instance.setSecurityRealm(hudsonRealm)

def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
instance.setAuthorizationStrategy(strategy)
instance.save()

0 comments on commit 84a7992

Please sign in to comment.