generated from Templates/Utility-Image-Builder
Initial commit
This commit is contained in:
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
@@ -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
|
||||
1
Dockerfile
Normal file
1
Dockerfile
Normal file
@@ -0,0 +1 @@
|
||||
FROM nginx:latest
|
||||
29
README.md
Normal file
29
README.md
Normal file
@@ -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.
|
||||
3
config.conf
Normal file
3
config.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
destinationRegistry=192.168.195.195:30000
|
||||
imageName=nginx
|
||||
imageTag=latest
|
||||
49
template/Jenkinsfile
vendored
Normal file
49
template/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
#!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 '''
|
||||
export destinationRegistry=`sed -n 's/^destinationRegistry=\\(.*\\)/\\1/p' < config.conf`
|
||||
export imageName=`sed -n 's/^imageName=\\(.*\\)/\\1/p' < config.conf`
|
||||
export imageTag=`sed -n 's/^imageTag=\\(.*\\)/\\1/p' < config.conf`
|
||||
/kaniko/executor --dockerfile `pwd`/Dockerfile --context `pwd` --destination ${destinationRegistry}/${imageName}:${imageTag}
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
template/setup.sh
Executable file
27
template/setup.sh
Executable file
@@ -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..."
|
||||
Reference in New Issue
Block a user