This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts and documentation for building a CentOS image.
Signed-off-by: dlorenc <[email protected]>
- Loading branch information
Showing
8 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ mkdebootstrap/mkimage/ | |
mkdebootstrap/Dockerfile | ||
bazel-* | ||
rootfs.tar.gz | ||
centos/layer.tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM scratch | ||
ADD layer.tar / | ||
CMD ["/bin/bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM centos | ||
COPY build.sh . | ||
COPY chroot.sh /target/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## CentOS | ||
|
||
This directory contains scripts and Dockerfiles for building a CentOS container image. | ||
|
||
### Overview | ||
|
||
We bootstrap the image following a process based on a combination of https://wiki.centos.org/HowTos/ManualInstall | ||
and https://github.com/CentOS/sig-cloud-instance-build/blob/master/docker/centos-7.ks. | ||
|
||
We avoid using kickstart to make it easier to run in a container environment like Cloud Build, but still reuse the | ||
package list and cleanup steps from the kickstart installation. | ||
|
||
To build an image: | ||
|
||
```shell | ||
gcloud builds submit --config=cloudbuild.yaml | ||
``` | ||
|
||
To build locally: | ||
|
||
```shell | ||
docker build . -f Dockerfile.build -t builder | ||
|
||
docker run --privileged -v $(pwd):/workspace builder /build.sh | ||
|
||
docker build . -t mycentosimage | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# This script sets up a bootstrapped CentOS chroot and saves it as a tarball. | ||
|
||
mkdir /target | ||
rpm --nodeps --root /target/ -i http://mirror.centos.org/centos/7/os/x86_64/Packages/centos-release-7-5.1804.el7.centos.x86_64.rpm | ||
cp -f /etc/resolv.conf /target/etc | ||
|
||
yum -q -y --installroot=/target --releasever=7 install yum | ||
cp -f /etc/yum.conf /target/etc/ | ||
mkdir -p /target/dev | ||
mount --bind /dev/ /target/dev/ | ||
mount -t proc procfs /target/proc/ | ||
mount -t sysfs sysfs /target/sys/ | ||
|
||
# Execute the chroot script. | ||
chroot /target ./chroot.sh | ||
|
||
# Cleanup and save as a tar. | ||
umount /target/dev/ | ||
umount /target/proc/ | ||
umount /target/sys/ | ||
rm /target/chroot.sh | ||
|
||
tar -C /target -cf /workspace/layer.tar . | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# This script runs inside a chroot and sets up a bootstrapped centos image. | ||
|
||
yum -y -q --releasever=7 install yum centos-release | ||
yum install -q -y bind-utils bash yum vim-minimal centos-release less iputils iproute systemd rootfiles tar passwd yum-utils yum-plugin-ovl hostname | ||
yum -q -y erase kernel* *firmware firewalld-filesystem os-prober gettext* GeoIP bind-license freetype libteam teamd | ||
rpm -e kernel | ||
yum -y remove bind-libs bind-libs-lite dhclient dhcp-common dhcp-libs dracut-network e2fsprogs e2fsprogs-libs ebtables ethtool file firewalld freetype gettext gettext-libs groff-base grub2 grub2-tools grubby initscripts iproute iptables kexec-tools libcroco libgomp libmnl libnetfilter_conntrack libnfnetlink libselinux-python lzo libunistring os-prober python-decorator python-slip python-slip-dbus snappy sysvinit-tools which linux-firmware GeoIP firewalld-filesystem qemu-guest-agent | ||
yum clean all | ||
rm -rf /var/cache/yum | ||
rm -rf /boot | ||
rm -rf /etc/firewalld | ||
passwd -l root | ||
echo 'container' > /etc/yum/vars/infra | ||
rm -rf /var/cache/yum/x86_64 | ||
rm -f /tmp/ks-script* | ||
rm -rf /etc/sysconfig/network-scripts/ifcfg-* | ||
rm -rf /etc/udev/hwdb.bin | ||
rm -rf /usr/lib/udev/hwdb.d/* | ||
:> /etc/machine-id | ||
umount /run | ||
systemd-tmpfiles --create --boot | ||
rm /var/run/nologin | ||
rpm --rebuilddb | ||
rm /etc/resolv.conf | ||
|
||
rm -rf /root/.bash_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
steps: | ||
- name: 'docker' | ||
args: ['build', '.', '-f', 'Dockerfile.build', '-t', 'builder'] | ||
- name: 'builder' | ||
args: ['/build.sh'] | ||
- name: 'docker' | ||
args: ['build', '.', '-t', 'gcr.io/$PROJECT_ID/centos7:$COMMIT_SHA'] | ||
images: ['gcr.io/$PROJECT_ID/centos7:$COMMIT_SHA'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
steps: | ||
- name: 'docker' | ||
args: ['build', '.', '-f', 'Dockerfile.build', '-t', 'builder'] | ||
- name: 'builder' | ||
args: ['/build.sh'] | ||
- name: 'docker' | ||
args: ['build', '.', '-t', 'gcr.io/$PROJECT_ID/centos7:$_TAG_NAME'] | ||
images: ['gcr.io/$PROJECT_ID/centos7:$_TAG_NAME'] |