Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding custom commands to Dockerfile's end #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion configs/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extra_packages="$extra_deb_packages"

# Opam switch to use. This determines the OCaml version and a set of
# configuration options.
opam_switch="4.14.0"
opam_switch="4.14.1"

# The collection of opam packages we want to install. Go wild.
opam_packages="$opam_packages"
2 changes: 2 additions & 0 deletions docker-build
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ build() {
cp -a src/os/"$os" tmp/os
cp -a src/opam tmp
cp -a src/create-dockerfile tmp
cp extra-docker-tail tmp/ -v

extra_build_options=()
for url in "${extra_docker_urls[@]}"; do
Expand All @@ -74,6 +75,7 @@ build() {
--create-user "$user" \
--extra-packages "$extra_packages" \
--opam-packages "$opam_packages" \
--extra-docker-tail ./extra-docker-tail \
--opam-switch "$opam_switch" \
--opam-switch-options "$opam_switch_options"
docker build -t "$docker_url" "${extra_build_options[@]}" .
Expand Down
10 changes: 10 additions & 0 deletions extra-docker-tail
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RUN echo "Manual commands in the end"

# Use the following to get a more compact image
RUN du -sh ~/.opam
RUN find $(opam var bin) -iname '*.byte' -exec rm -fv {} \;
RUN find $(opam var bin) -iname 'ocamlformat.parser_recover.test*' -exec rm -f {} \;
RUN find $(opam var lib) -iname '*.cmt' -exec rm -f {} \;
RUN find $(opam var lib) -iname '*.cmti' -exec rm -f {} \;
RUN find $(opam var prefix) -iname '*.exe' -exec strip {} \;
RUN du -sh ~/.opam
Copy link
Owner

Choose a reason for hiding this comment

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

This seems like a good idea but it won't reduce the image size unless we do something to squash the layers. Maybe there's a tool for this?

11 changes: 11 additions & 0 deletions src/create-dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ from=''
no_from=false
create_user=''
dockerfile=''
extra_docker_tail=''
extra_packages="$default_extra_packages"
force_tag=''
opam_packages="$default_opam_packages"
Expand Down Expand Up @@ -144,6 +145,10 @@ while [[ $# -gt 0 ]]; do
opam_switch_options=$(echo $2)
shift
;;
--extra-docker-tail)
extra_docker_tail=$(echo $2)
shift
;;
--os)
os=$2
case "$os" in
Expand Down Expand Up @@ -236,3 +241,9 @@ $([[ "$no_cmd" = true ]] || (echo; echo "CMD $cmd") )

COPY Dockerfile /Dockerfile
EOF

if [ -z "$extra_docker_tail" ]; then
echo "No extra docker contents specified" 1>&2
else
cat "$extra_docker_tail" >> $dockerfile
fi