Skip to content

Instantly share code, notes, and snippets.

@l0rd

l0rd/Dockerfile Secret

Last active October 9, 2018 13:04
Show Gist options
  • Save l0rd/5a3501dd250ffe902bf7eb7294624c9a to your computer and use it in GitHub Desktop.
Save l0rd/5a3501dd250ffe902bf7eb7294624c9a to your computer and use it in GitHub Desktop.
Rootless build of a simple docker image

Build an image with umoci and skopeo

docker build -t mariolet/umoci .
docker push mariolet/umoci

Login to the OpenShift cluster and start the container based on the image we just built

oc login <OPENSHIFT_API> -t <TOKEN>
oc run -i -t test --image=mariolet/umoci \
                  --restart=Never --rm=true \
                  --command -- bash

Git clone a plugin project

mkdir -p /tmp/project && cd /tmp/project/
export GIT_COMMITTER_NAME=l0rd && \
export GIT_COMMITTER_EMAIL=mario.loriedo@gmail.com && \
git clone https://github.com/ws-skeleton/che-service-plugin.git && \
cd che-service-plugin/service/

Build the image

# Set DockerHub credentials
DOCKERHUB_USER=<login>
DOCKERHUB_PASSWORD=<password>

# Pull and unpackl the base image (node:10.7-alpine)
skopeo copy docker://node:10.7-alpine oci:che-hello-plugin:latest && \
umoci unpack --rootless --image che-hello-plugin:latest bundle

# COPY
mkdir ./bundle/rootfs/server && \
   cp -r impl/* ./bundle/rootfs/server/

# RUN
cd ./bundle/rootfs/server/ && \
  HOME=/tmp/project/ yarn install && \
  cd -

# Repack and push the resluting image to Docker Hub
umoci repack --image che-hello-plugin:new bundle
skopeo copy --dcreds $DOCKERHUB_USER:$DOCKERHUB_PASSWORD \
             oci:che-hello-plugin:new \
             docker://$DOCKERHUB_USER/che-hello-plugin:new
FROM centos
# Add yarn repo
RUN curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
# Install nodejs/npm/yarn
RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
RUN yum -y update && yum -y install skopeo nodejs yarn patch git
RUN curl -sSL -o /usr/local/bin/umoci https://github.com/openSUSE/umoci/releases/download/v0.4.2/umoci.amd64 && chmod +x /usr/local/bin/umoci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment