Skip to content

Commit c91c79d

Browse files
authored
Merge pull request #66 from frmscoe/create-building-the-jenkins-image
docs: Create building-the-jenkins-image.md
2 parents 81b8f01 + 7686247 commit c91c79d

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!-- SPDX-License-Identifier: Apache-2.0 -->
2+
3+
To install and push the provided script to a container registry, follow these steps. This guide assumes you have Docker installed on your desktop and have access to a container registry where you can push images.
4+
5+
## 1. Preparing Your Environment
6+
7+
Before you begin, ensure you have Docker installed on your desktop. Docker will be used to build and push your Docker image. If you haven't installed Docker, visit the official Docker website for installation instructions for your operating system.
8+
9+
## 2. Creating the Script
10+
11+
1. Open your preferred text editor.
12+
2. Copy and paste the provided Bash script into the editor. Or create a Dockerfile and run that.
13+
14+
```dockerfile
15+
# Use a base Jenkins agent image
16+
FROM jenkins/inbound-agent:latest as jnlp
17+
18+
USER root
19+
20+
# Update and install necessary packages for adding new repositories
21+
RUN apt-get update && apt-get install -y \
22+
apt-transport-https \
23+
gnupg2 \
24+
curl \
25+
sudo
26+
27+
# Add Kubernetes package key and set up the repository
28+
#RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg
29+
#RUN echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-bionic main" > /etc/apt/sources.list.d/kubernetes.list
30+
RUN echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
31+
RUN curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
32+
33+
RUN apt-get update
34+
35+
# Update and install kubectl
36+
RUN apt-get update -qq && apt-get install -qq -y kubectl
37+
38+
# Install Buildah
39+
RUN apt-get install -y buildah
40+
41+
# Switch back to the jenkins user
42+
USER jenkins
43+
```
44+
45+
3. Save the file with a recognizable name, for example, build_and_push.sh. Ensure you have execution permission set on the script. You can set execute permission by running chmod +x build_and_push.sh in your terminal.
46+
47+
## 3. Running the Script
48+
49+
Before running the script, replace ${ImageRepository} with your actual container registry repository path. For example, if you are using Docker Hub, it might look like username/jenkins-inbound-agent.
50+
51+
To run the script:
52+
53+
1. Open a terminal or command prompt.
54+
2. Navigate to the directory where you saved build_and_push.sh.
55+
3. Execute the script by typing ./build_and_push.sh and press Enter.
56+
57+
This script performs the following actions:
58+
- Generates a Dockerfile that uses jenkins/inbound-agent:1.0.0as the base image.
59+
- Installs kubectl and buildah inside the Docker image.
60+
- Builds a new Docker image tagged as jenkins-inbound-agent:1.0.0in your specified image repository.
61+
- Pushes the newly built Docker image to the container registry.
62+
63+
## 4. Pushing to a Container Registry
64+
65+
The script automatically pushes the Docker image to the container registry specified in the ${ImageRepository} variable. Ensure you are logged in to your Docker or container registry account. You can log in to Docker Hub by running docker login and entering your credentials. For other registries, the login command might differ slightly, so refer to the registry's documentation for the exact command.
66+
67+
## 5. Verifying the Push
68+
69+
After the script completes, verify that the image has been successfully pushed to your container registry:
70+
71+
- For Docker Hub, visit https://hub.docker.com/r/<your-username> and check if the jenkins-inbound-agent:1.0.0image is listed.
72+
- For other container registries, use the registry's web interface or CLI tools to verify the image is present.
73+
74+
## Troubleshooting
75+
76+
- **Permission Denied**: If you encounter a permission denied error when running the script, ensure you've set the execute permission with chmod +x build_and_push.sh.
77+
- **Docker Not Running**: Ensure Docker is running on your desktop. If it's not, start Docker through your system's services interface.
78+
- **Login Required**: If the push to the container registry fails, make sure you're logged in to your container registry account.
79+
80+
By following these steps, you will have successfully installed the script locally and pushed the Docker image through to a container registry.

0 commit comments

Comments
 (0)