Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Add Dockerfile and Dockertag generation from templates #12

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
28 changes: 9 additions & 19 deletions build-all.bash
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
#!/bin/bash
#!/usr/bin/env bash

set -vex
casperdcl marked this conversation as resolved.
Show resolved Hide resolved

# This script builds all Docker containers described by Dockerfiles in this repository
# For each Dockerfile it runs:
# $ docker build -t $TAGPREFIX/$TAG
# and
# $ docker push -t $TAGPREFIX/$TAG
#
# $TAGPREFIX is defined in this file.
# If a Dockerfile has a Dockertag file in the same directory, it's read from there
# Otherwise $TAG is generated by replacing / and <space> with - in the directory name.
#
# docker build command uses --no-cache option to prevent stale layers to be used.
HERE="$( cd "$(dirname "$0")" ; pwd -P )"

export RELEASE_HASH="${RELEASE_HASH:-$(curl -s https://api.github.com/repos/iterative/dvc/releases/latest | sha256sum | cut -c -8)}"
export TAG_PREFIX="${TAG_PREFIX:-dvcorg}"

set -vex

RELEASE_HASH=$(curl -s https://api.github.com/repos/iterative/dvc/releases/latest | sha256sum | cut -c -8)
./generate-all.bash

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create a separate generate-all.bash yet not use it anywhere else? Either keep things in one file or re-use them in multiple places, surely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this call to generate-all.bash. For debugging and security, generate, build, push should be called separately IMO.


TAGPREFIX=dvcorg
DIR=$(dirname $0)
cd "${DIR}"

Expand All @@ -29,8 +21,6 @@ find $DIR -name Dockerfile | sort | while read -r filepath ; do
else
TAG=$(echo "${dockerdir}[3,100]}" | tr '/ ' '--')
fi
echo "BUILDING: ${dockerdir} with the tag: ${TAGPREFIX}/${TAG}"
docker build --build-arg RELEASE_HASH=${RELEASE_HASH} -t ${TAGPREFIX}/${TAG} ${dockerdir}/
echo "PUSHING: ${dockerdir} with the tag: ${TAGPREFIX}/${TAG}"
docker push ${TAGPREFIX}/${TAG}
echo "BUILDING: ${dockerdir} with the tag: ${TAG_PREFIX}/${TAG}"
docker build --build-arg RELEASE_HASH=${RELEASE_HASH} -t ${TAG_PREFIX}/${TAG} ${dockerdir}/
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
done
30 changes: 30 additions & 0 deletions generate-all.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -vex

HERE="$( cd "$(dirname "$0")" ; pwd -P )"
export RELEASE_HASH="${RELEASE_HASH:-$(curl -s https://api.github.com/repos/iterative/dvc/releases/latest | sha256sum | cut -c -8)}"
export TAG_PREFIX="${TAG_PREFIX:-dvcorg}"

DIR=$(dirname $0)
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
cd "${DIR}"
casperdcl marked this conversation as resolved.
Show resolved Hide resolved

find ${DIR} -name generate.* | sort | while read -r filepath ; do
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
filename=$(basename -- "$filepath")
dirname=$(dirname -- "$filepath")
ext="${filename##*.}"
cd $dirname
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
if [[ "$ext" == "bash" ]] ; then
bash "$filename"
elif [[ "$ext" == "sh" ]] ; then
sh "$filename"
elif [[ "$ext" == "zsh" ]] ; then
zsh "$filename"
elif [[ "$ext" == "py" ]] ; then
python "$filename"
else
echo "UNSUPPORTED GENERATOR SCRIPT: $filepath"
fi
cd -
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
done

casperdcl marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions katacoda/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dvc-get-started/
build/
1 change: 0 additions & 1 deletion katacoda/Dockertag

This file was deleted.

1 change: 0 additions & 1 deletion katacoda/Dockerfile → katacoda/base/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ WORKDIR /root
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

ARG RELEASE_HASH

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this?

RUN RELEASE_HASH=${RELEASE_HASH} \
apt-get update -y && apt-get install -y \
gnupg \
Expand Down
1 change: 1 addition & 0 deletions katacoda/base/Dockertag.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${TAG_PREFIX}/doc-katacoda:base
File renamed without changes.
29 changes: 29 additions & 0 deletions katacoda/generate.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -vex

HERE="$( cd "$(dirname "$0")" ; pwd -P )"

if [[ -d ${HERE}/build ]] ; then
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
echo "Please delete ${PWD}/build directory first."
exit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exit
exit 1

fi

export RELEASE_HASH="${RELEASE_HASH:-$(curl -s https://api.github.com/repos/iterative/dvc/releases/latest | sha256sum | cut -c -8)}"
export TAG_PREFIX="${TAG_PREFIX:-dvcorg}"

find ${HERE} -name Dockerfile.template | sort | while read -r filepath ; do
ABSOLUTE_SOURCE=$(dirname "$filepath")
SOURCE_DIR=$(realpath --relative-to=${HERE} ${ABSOLUTE_SOURCE})
TARGET_DIR=${HERE}/build/${SOURCE_DIR}
if [ ! -d ${TARGET_DIR} ] ; then
mkdir -p ${TARGET_DIR}
fi
cp -fr ${ABSOLUTE_SOURCE}/* ${TARGET_DIR}
cat ${ABSOLUTE_SOURCE}/Dockerfile.template | envsubst > ${TARGET_DIR}/Dockerfile
cat ${ABSOLUTE_SOURCE}/Dockertag.template | envsubst > ${TARGET_DIR}/Dockertag
rm -f ${TARGET_DIR}/Dockerfile.template
rm -f ${TARGET_DIR}/Dockertag.template
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
done

unset RELEASE_HASH
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM dvcorg/doc-katacoda:base
FROM ${TAG_PREFIX}/doc-katacoda:base


RUN RELEASE_HASH=${RELEASE_HASH} \
Expand Down
1 change: 0 additions & 1 deletion katacoda/get-started/01-initialize/Dockertag

This file was deleted.

1 change: 1 addition & 0 deletions katacoda/get-started/01-initialize/Dockertag.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${TAG_PREFIX}/doc-katacoda:start-initialize
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM dvcorg/doc-katacoda:base
FROM ${TAG_PREFIX}/doc-katacoda:base

RUN RELEASE_HASH=${RELEASE_HASH} \
git clone https://github.com/iterative/example-get-started \
Expand Down
1 change: 0 additions & 1 deletion katacoda/get-started/02-versioning/Dockertag

This file was deleted.

1 change: 1 addition & 0 deletions katacoda/get-started/02-versioning/Dockertag.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${TAG_PREFIX}/doc-katacoda:start-versioning
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM dvcorg/doc-katacoda:base
FROM ${TAG_PREFIX}/doc-katacoda:base

ARG RELEASE_HASH

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove? (also same with all other similar cases...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because these are set by environment variables now, with envsubst in generate.bash. Previously RELEASE_HASH was supplied as --build-arg in docker build. ARG in Dockerfile is misleading.

RUN RELEASE_HASH=${RELEASE_HASH} \
apt-get update -y && apt-get install -y \
python3 \
Expand Down
1 change: 0 additions & 1 deletion katacoda/get-started/03-accessing/Dockertag

This file was deleted.

1 change: 1 addition & 0 deletions katacoda/get-started/03-accessing/Dockertag.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${TAG_PREFIX}/doc-katacoda:start-accessing
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM dvcorg/doc-katacoda:base
FROM ${TAG_PREFIX}/doc-katacoda:base


ARG RELEASE_HASH
RUN RELEASE_HASH=${RELEASE_HASH} \
git clone \
https://github.com/iterative/example-get-started \
Expand Down
1 change: 0 additions & 1 deletion katacoda/get-started/04-stages/Dockertag

This file was deleted.

1 change: 1 addition & 0 deletions katacoda/get-started/04-stages/Dockertag.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${TAG_PREFIX}/doc-katacoda:start-stages
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM dvcorg/doc-katacoda:base
FROM ${TAG_PREFIX}/doc-katacoda:base

ARG RELEASE_HASH
RUN RELEASE_HASH=${RELEASE_HASH} \
git clone \
https://github.com/iterative/example-get-started \
Expand Down
1 change: 0 additions & 1 deletion katacoda/get-started/05-params-metrics-plots/Dockertag

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${TAG_PREFIX}/doc-katacoda:start-params
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM dvcorg/doc-katacoda:base
FROM ${TAG_PREFIX}/doc-katacoda:base

ARG RELEASE_HASH
RUN RELEASE_HASH=${RELEASE_HASH} \
git clone \
https://github.com/iterative/dvc-get-started --branch evaluation \
Expand All @@ -19,9 +18,6 @@ RUN RELEASE_HASH=${RELEASE_HASH} \
&& pip3 install -r requirements.txt


# RUN RELEASE_HASH=${RELEASE_HASH} \
# dvc pull

COPY start.sh /root/start.sh

EXPOSE 80
Expand Down
1 change: 0 additions & 1 deletion katacoda/get-started/06-experiments/Dockertag

This file was deleted.

1 change: 1 addition & 0 deletions katacoda/get-started/06-experiments/Dockertag.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${TAG_PREFIX}/doc-katacoda:start-experiments
27 changes: 27 additions & 0 deletions push-all.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -vex

HERE="$( cd "$(dirname "$0")" ; pwd -P )"
export RELEASE_HASH="${RELEASE_HASH:-$(curl -s https://api.github.com/repos/iterative/dvc/releases/latest | sha256sum | cut -c -8)}"
export TAG_PREFIX="${TAG_PREFIX:-dvcorg}"

DIR=$(dirname $0)
cd "${DIR}"

find $DIR -name Dockerfile | sort | while read -r filepath ; do
dockerdir=$(dirname ${filepath})
tagfile=${dockerdir}/Dockertag
if [ -f ${tagfile} ] ; then
TAG=$(head -n 1 ${tagfile})
else
TAG=$(echo "${dockerdir}[3,100]}" | tr '/ ' '--')
fi
if [[ "${TAG}" ~= '.*/.*' ]] ; then
echo "PUSHING: ${dockerdir} with the tag: ${TAG}"
docker push ${TAG}
else
echo "PUSHING: ${dockerdir} with the tag: ${TAG_PREFIX}/${TAG}"
docker push ${TAG_PREFIX}/${TAG}
fi
done
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions start/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dvc-get-started/
build/
17 changes: 5 additions & 12 deletions start/Dockerfile → start/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
FROM ubuntu:20.04
FROM python:3.8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • does the katacode base have to be changed as well?
  • should this be slim?
Suggested change
FROM python:3.8
FROM python:3.8-slim


WORKDIR /root

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

ARG RELEASE_HASH
RUN RELEASE_HASH=${RELEASE_HASH} \
apt-get update -y && apt-get install -y \
gnupg \
wget \
tree

RUN wget \
https://dvc.org/deb/dvc.list \
-O /etc/apt/sources.list.d/dvc.list

RUN wget -qO - https://dvc.org/deb/iterative.asc | apt-key add -


RUN RELEASE_HASH=${RELEASE_HASH} \
apt-get update -y && apt-get install -y \
dvc
pip install 'dvc[all]'

COPY bashrc .bashrc
COPY dvc-get-started dvc-get-started
COPY .bashrc .bashrc

# Configure git user name and email
RUN git config --global user.email "[email protected]" \
Expand Down
1 change: 0 additions & 1 deletion start/Dockertag

This file was deleted.

1 change: 1 addition & 0 deletions start/Dockertag.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dvcorg/doc-start:${GIT_TAG}
30 changes: 30 additions & 0 deletions start/generate.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash


HERE="$( cd "$(dirname "$0")" ; pwd -P )"

if [[ -d build ]] ; then
echo "Please delete ${PWD}/build directory first."
exit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exit
exit 1

fi

# Clone dvc-get-started
git clone https://github.com/iterative/dvc-get-started

GIT_TAGS=$(git -C dvc-get-started tag --list)

for TAG in ${GIT_TAGS} ; do
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
TAG_DIR="build/${TAG}"
mkdir -p ${TAG_DIR}

export GIT_TAG=${TAG}

git clone dvc-get-started -b ${GIT_TAG} ${TAG_DIR}/dvc-get-started

cp bashrc ${TAG_DIR}/.bashrc
cat Dockerfile.template | envsubst > ${TAG_DIR}/Dockerfile
cat Dockertag.template | envsubst > ${TAG_DIR}/Dockertag
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
done

unset GIT_TAG
unset RELEASE_HASH