commit 3c72161a18637e7541d98bcaba1622d3906f7e93 Author: Home-Cluster <> Date: Wed Jan 11 21:34:02 2023 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4777d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# ---> macOS +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e600c7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +FROM nginx:latest \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..422b6fd --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Utility-Image-Builder + +A template repo for maintaining base Docker images in my private registry. + +> NOTE: The steps below are not for this repo, but for those using it as a template. + +## Bootstrapping +> If needed, steps starting with `[sudo]` require elevated permissions. + +> Go through the entire process before committing to the main branch. + +1. Create a new repository by clicking the "Use this template" button on the template repo page. +1. Configure the new repo settings. At the bottom, select `Template Items` -> `Git Content`. +1. Create the new repo. +1. Pull new repo to local PC. +1. [sudo] Give the setup script permission to execute: + ```bash + chmod +x template/setup.sh + ``` +1. [sudo] Run the start script and fill in the prompts: + ```bash + ./template/setup.sh + ``` +1. Change the Dockerfile as desired. NOTE: Committing before doing this will still build an image... +1. Populate the `config.json`. This is to make it easy to do version management +1. Commit to main. If you are committing to an organization linked to the Jenkins server the image will automatically be build for +the architecture you specified. + +> Note that the bootstrapped repo has to be in a organization where the Jenkins user has visibility, and the organization must be configured and linked to the Jenkins server. \ No newline at end of file diff --git a/config.conf b/config.conf new file mode 100644 index 0000000..5d50dbb --- /dev/null +++ b/config.conf @@ -0,0 +1,3 @@ +destinationRegistry=192.168.195.195:30000 +imageName=nginx +imageTag=latest \ No newline at end of file diff --git a/template/Jenkinsfile b/template/Jenkinsfile new file mode 100644 index 0000000..ef796ae --- /dev/null +++ b/template/Jenkinsfile @@ -0,0 +1,47 @@ +#!groovy + +pipeline { + agent { + kubernetes { + defaultContainer 'jnlp' + yaml """ +apiVersion: v1 +kind: Pod +metadata: + name: {{k3sApp}}-image-build +spec: + serviceAccountName: jenkins-admin + nodeSelector: + kubernetes.io/arch: {{k3sArch}} + containers: + - name: kaniko + image: gcr.io/kaniko-project/executor:debug + command: ["tail"] + args: ["-f", "/dev/null"] + volumeMounts: + - name: kaniko-secret + mountPath: /kaniko/.docker + restartPolicy: Never + volumes: + - name: kaniko-secret + secret: + secretName: dockercred + items: + - key: .dockerconfigjson + path: config.json + """ + } + } + stages { + stage('Docker Build and Push') { + steps { + container("kaniko") { + sh 'destinationRegistry=`sed -n \'s/^destinationRegistry=\(.*\)/\1/p\' < config.conf`' + sh 'imageName=`sed -n \'s/^imageName=\(.*\)/\1/p\' < config.conf`' + sh 'imageTag=`sed -n \'s/^imageTag=\(.*\)/\1/p\' < config.conf`' + sh '/kaniko/executor --dockerfile `pwd`/Dockerfile --context `pwd` --destination ${destinationRegistry}/${imageName}:${imageTag}' + } + } + } + } +} \ No newline at end of file diff --git a/template/setup.sh b/template/setup.sh new file mode 100755 index 0000000..dd88cc1 --- /dev/null +++ b/template/setup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +echo "Hello, lets get your project set up. Please follow the prompts attentively." + +echo "" +read -p " K3S Build Pod Name: " k3sApp +read -p " Build Architecture: [amd64 | arm64] " k3sArch + +echo "" +echo "Creating Folders" + echo " Creating cicd/" + mkdir cicd + +echo "" +echo "Loading files" +echo " Loading cicd/Jenkinsfile" +cp template/Jenkinsfile cicd/Jenkinsfile +sed -ie "s|{{k3sApp}}|$k3sApp|g" cicd/Jenkinsfile +sed -ie "s|{{k3sArch}}|$k3sArch|g" cicd/Jenkinsfile +rm cicd/Jenkinsfilee + +echo "" +echo "Removing template folder" +# rm -rf template + +echo "" +echo "Thank you! Happy building..."