This commit is contained in:
2024-02-20 17:15:27 +08:00
committed by huty
parent 6706e1a633
commit 34158042ad
1529 changed files with 177765 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
ARG ALPINE_VERSION="3.15"
FROM alpine:$ALPINE_VERSION AS download-base
WORKDIR /downloads
RUN echo "$(apk --print-arch)" > /arch.txt
RUN ARCH2= && alpineArch="$(apk --print-arch)" \
&& case "${alpineArch##*-}" in \
x86_64) ARCH2='amd64' ;; \
aarch64) ARCH2='arm64' ;; \
*) echo "unsupported architecture"; exit 1 ;; \
esac && \
echo $ARCH2 > /arch2.txt
FROM download-base AS packages
ARG KUBECTL_VERSION="1.24.4-r0"
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
kubectl=$KUBECTL_VERSION
FROM download-base AS buildkit
ARG BUILDKIT_VERSION="v0.9.0"
RUN wget -O buildkit.tar.gz "https://github.com/moby/buildkit/releases/download/$BUILDKIT_VERSION/buildkit-$BUILDKIT_VERSION.linux-$(cat /arch2.txt).tar.gz"
RUN tar xvf buildkit.tar.gz
FROM download-base AS helm
ARG HELM_VERSION="v3.6.2"
RUN wget -O helm.tar.gz "https://get.helm.sh/helm-$HELM_VERSION-linux-$(cat /arch2.txt).tar.gz"
RUN tar xvf helm.tar.gz --strip-components 1
FROM download-base AS jenkins
ARG JENKINS_VERSION="2.319.1"
RUN wget http://mirrors.jenkins.io/war-stable/$JENKINS_VERSION/jenkins.war
# Jenkins
FROM alpine:$ALPINE_VERSION
# jenkins deps
RUN apk add --no-cache \
bash \
coreutils \
jq \
git \
openjdk11 \
openssh-client \
ttf-dejavu \
unzip
ENV JENKINS_HOME="/data"
VOLUME ${JENKINS_HOME}
EXPOSE 8080
ENTRYPOINT /start.sh
COPY --from=packages /usr/bin/kubectl /usr/bin/kubectl
COPY --from=buildkit /downloads/bin/buildctl /usr/bin/buildctl
COPY --from=helm /downloads/helm /usr/bin/helm
COPY --from=jenkins /downloads/jenkins.war /jenkins/jenkins.war
COPY ./jenkins.install.UpgradeWizard.state ${JENKINS_HOME}/
COPY ./scripts/ ${JENKINS_HOME}/init.groovy.d/
COPY start.sh /
RUN chmod +x /start.sh

View File

@@ -0,0 +1,23 @@
#!groovy
import jenkins.install.*;
import jenkins.model.*
import jenkins.security.s2m.AdminWhitelistRule
import hudson.security.*
import hudson.util.*;
def instance = Jenkins.getInstance()
def username = "kiamol"
def password = "kiamol"
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount(username, password)
instance.setSecurityRealm(hudsonRealm)
def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
instance.setAuthorizationStrategy(strategy)
instance.setInstallState(InstallState.INITIAL_SETUP_COMPLETED)
instance.save()
Jenkins.instance.getInjector().getInstance(AdminWhitelistRule.class).setMasterKillSwitch(false)

View File

@@ -0,0 +1,15 @@
#!groovy
import jenkins.model.Jenkins;
pm = Jenkins.instance.pluginManager
uc = Jenkins.instance.updateCenter
pm.doCheckUpdatesServer()
["git", "workflow-aggregator"].each {
if (! pm.getPlugin(it)) {
deployment = uc.getPlugin(it).deploy(true)
deployment.get()
}
}

View File

@@ -0,0 +1,26 @@
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
import hudson.plugins.git.*;
import hudson.triggers.SCMTrigger;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
def gitUser = "kiamol"
def gitRepo = "kiamol"
def gitUrl = "http://gogs:3000/${gitUser}/${gitRepo}.git"
def jenkins = Jenkins.instance;
def scm = new GitSCM(gitUrl)
scm.branches = [new BranchSpec("*/master")];
def workflowJob = new WorkflowJob(jenkins, "${gitRepo}");
workflowJob.definition = new CpsScmFlowDefinition(scm, "ch11/bulletin-board/Jenkinsfile");
def gitTrigger = new SCMTrigger("* * * * *");
workflowJob.addTrigger(gitTrigger);
workflowJob.disabled = true;
workflowJob.save();
jenkins.reload()

View File

@@ -0,0 +1,17 @@
#!/bin/sh
# set up access to Kube API
kubectl config set-cluster default --server=https://kubernetes.default.svc.cluster.local --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
kubectl config set-context default --cluster=default
kubectl config set-credentials user --token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
kubectl config set-context default --user=user
kubectl config use-context default
# promote registry details to env:
registry=$(cat ~/.docker/config.json | jq '.auths' | jq 'keys[0]' -r)
if [ "$registry" = "https://index.docker.io/v1/" ]; then export REGISTRY_SERVER='docker.io'; else export REGISTRY_SERVER=$registry; fi
export REGISTRY_USER=$(cat ~/.docker/config.json | jq '.auths[].username' -r)
echo "*** Using registry: $REGISTRY_SERVER, with user: $REGISTRY_USER ***"
# run Jenkins
java -Duser.home=${JENKINS_HOME} -Djenkins.install.runSetupWizard=false -jar /jenkins/jenkins.war