commit b75dcc92cfd1b4aaa705facd9da47963676b0bfb Author: yukumi.okada Date: Tue Nov 12 16:49:27 2024 +0900 first commit diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..b2f83f4 --- /dev/null +++ b/compose.yml @@ -0,0 +1,80 @@ +services: + jenkins1: + image: jenkins/jenkins:lts + container_name: jenkins1 + ports: + - "8081:8080" + volumes: + - jenkins_home1:/var/jenkins_home + - ./init.groovy.d:/var/jenkins_home/init.groovy.d + environment: + - JENKINS_USER=admin + - JENKINS_PASS=password + networks: + - jenkins_network + + jenkins2: + image: jenkins/jenkins:lts + container_name: jenkins2 + ports: + - "8082:8080" + volumes: + - jenkins_home2:/var/jenkins_home + - ./init.groovy.d:/var/jenkins_home/init.groovy.d + environment: + - JENKINS_USER=admin + - JENKINS_PASS=password + networks: + - jenkins_network + + jenkins3: + image: jenkins/jenkins:lts + container_name: jenkins3 + ports: + - "8083:8080" + volumes: + - jenkins_home3:/var/jenkins_home + - ./init.groovy.d:/var/jenkins_home/init.groovy.d + environment: + - JENKINS_USER=admin + - JENKINS_PASS=password + networks: + - jenkins_network + + jenkins4: + image: jenkins/jenkins:lts + container_name: jenkins4 + ports: + - "8084:8080" + volumes: + - jenkins_home4:/var/jenkins_home + - ./init.groovy.d:/var/jenkins_home/init.groovy.d + environment: + - JENKINS_USER=admin + - JENKINS_PASS=password + networks: + - jenkins_network + + jenkins5: + image: jenkins/jenkins:lts + container_name: jenkins5 + ports: + - "8085:8080" + volumes: + - jenkins_home5:/var/jenkins_home + - ./init.groovy.d:/var/jenkins_home/init.groovy.d + environment: + - JENKINS_USER=admin + - JENKINS_PASS=password + networks: + - jenkins_network + +volumes: + jenkins_home1: + jenkins_home2: + jenkins_home3: + jenkins_home4: + jenkins_home5: + +networks: + jenkins_network: diff --git a/init.groovy.d/basic-security.groovy b/init.groovy.d/basic-security.groovy new file mode 100644 index 0000000..9fb8d76 --- /dev/null +++ b/init.groovy.d/basic-security.groovy @@ -0,0 +1,20 @@ +import jenkins.model.* +import hudson.security.* + +def instance = Jenkins.getInstance() + +// ユーザー名とパスワードを設定 +def adminUsername = System.getenv("JENKINS_USER") ?: "admin" +def adminPassword = System.getenv("JENKINS_PASS") ?: "password" + +// セキュリティ設定を行い、管理者アカウントを作成 +def hudsonRealm = new HudsonPrivateSecurityRealm(false) +hudsonRealm.createAccount(adminUsername, adminPassword) +instance.setSecurityRealm(hudsonRealm) + +// 全ユーザーにアクセス権を付与 +def strategy = new FullControlOnceLoggedInAuthorizationStrategy() +strategy.setAllowAnonymousRead(false) +instance.setAuthorizationStrategy(strategy) + +instance.save() diff --git a/init.groovy.d/customize-jenkins.groovy b/init.groovy.d/customize-jenkins.groovy new file mode 100644 index 0000000..5a4c9a2 --- /dev/null +++ b/init.groovy.d/customize-jenkins.groovy @@ -0,0 +1,37 @@ +import jenkins.model.* +import hudson.security.* +import jenkins.install.InstallState + +def instance = Jenkins.getInstance() + +// プラグインの自動インストール +def pluginManager = instance.getPluginManager() +def updateCenter = instance.getUpdateCenter() +updateCenter.updateAllSites() + +// インストールするプラグインのリスト +def plugins = [ + "git", + "workflow-aggregator", + "credentials-binding", + "docker-plugin", + "docker-workflow", + "blueocean", + "slack-notification", + "pipeline-stage-view", + "email-ext" +] + +// プラグインがインストールされていない場合はインストール +plugins.each { + if (!pluginManager.getPlugin(it)) { + def plugin = updateCenter.getPlugin(it) + if (plugin) { + plugin.deploy() + } + } +} + +// 初期セットアップの完了状態に設定 +instance.setInstallState(InstallState.INITIAL_SETUP_COMPLETED) +instance.save()