Skip to content

Commit

Permalink
Merge pull request #48 from pabrahamsson/ubi_prune_image
Browse files Browse the repository at this point in the history
Use UBI for project prune image
  • Loading branch information
tylerauerbeck authored May 14, 2020
2 parents e9f9551 + 528ed6a commit 92aa779
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
This repo contains a set of general _good practice_ jobs that can be used as a starting point for operationalizing an OpenShift Container Platform cluster. This repo breaks down into several categories:

- *jobs* - a set of _jobs_ (including _CronJob_) templates for common tasks

- *images* - utility images for common tasks
7 changes: 7 additions & 0 deletions images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Images

This directory contains a collection of utility images for Openshift tasks.

### Prune Openshift projects

The [prune-ocp-projects](prune-ocp-projects) declaratively prunes projects based on creation date. Projects can beexcluded from being pruned by annotating the project or by excluding it based on name.
6 changes: 3 additions & 3 deletions images/prune-ocp-projects/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM centos:7
FROM registry.access.redhat.com/ubi8/ubi

LABEL io.k8s.description="OCP Project Pruner" \
io.k8s.display-name="OCP Project Pruner"
Expand All @@ -7,7 +7,7 @@ ENV PATH=$PATH:/usr/local/bin

ADD include/prune-ocp-projects.sh /usr/local/bin/

RUN curl https://mirror.openshift.com/pub/openshift-v3/clients/3.9.19/linux/oc.tar.gz | tar -C /usr/local/bin/ -xzf -
RUN chmod +x /usr/local/bin/prune-ocp-projects.sh
RUN curl https://mirror.openshift.com/pub/openshift-v4/clients/oc/4.4/linux/oc.tar.gz | tar -C /usr/local/bin/ -xzf - && \
chmod +x /usr/local/bin/prune-ocp-projects.sh

CMD [ "/usr/local/bin/prune-ocp-projects.sh" ]
22 changes: 22 additions & 0 deletions images/prune-ocp-projects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Prune OCP projects

Use this image to prune Openshift projects

- Based on UBI 8
- Uses oc client 4.4

## Build image

### Dockerfile
```
docker build -t prune-ocp-projects .
```

### Buildah
```
./buildah.sh
```
or
```
buildah build -t prune-ocp-projects .
```
14 changes: 14 additions & 0 deletions images/prune-ocp-projects/buildah.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -o errexit

# Create the container
container=$(buildah from registry.access.redhat.com/ubi8/ubi)
buildah config --label io.k8s.description="OCP Project Pruner" --label io.k8s.display-name="OCP Project Pruner" --env PATH='$PATH:/usr/local/bin' $container
buildah add $container include/prune-ocp-projects.sh /usr/local/bin/
buildah run $container -- curl -Lo /tmp/oc.tar.gz https://mirror.openshift.com/pub/openshift-v4/clients/oc/4.4/linux/oc.tar.gz
buildah run $container -- tar -C /usr/local/bin/ -xzf /tmp/oc.tar.gz
buildah run $container -- rm /tmp/oc.tar.gz
buildah config --cmd /usr/local/bin/prune-ocp-projects.sh $container

buildah commit $container prune-ocp-projects:latest

0 comments on commit 92aa779

Please sign in to comment.