Initial Commit
This commit is contained in:
1
Dockerfile
Normal file
1
Dockerfile
Normal file
@@ -0,0 +1 @@
|
|||||||
|
FROM nginx:latest
|
||||||
28
README.md
28
README.md
@@ -1,3 +1,29 @@
|
|||||||
# Utility-Image-Builder
|
# Utility-Image-Builder
|
||||||
|
|
||||||
A template repo for maintaining base Docker images in my private registry.
|
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
|
||||||
47
template/Jenkinsfile
vendored
Normal file
47
template/Jenkinsfile
vendored
Normal file
@@ -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}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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