forked from mjambon/ocaml-layer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-build
executable file
·98 lines (84 loc) · 2.12 KB
/
docker-build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /usr/bin/env bash
#
# Build or update Docker images locally.
# From https://github.com/mjambon/setup-ocaml
#
# Usage: ./docker-build [CONFIG_FILE1 CONFIG_FILE2 ...]
#
# Each config file is used separately to build a Docker image.
# If no argument is given, a single config file 'config.sh' is assumed.
#
# The list of destination docker URLs (tags) is saved to a temporary file
# which will be consulted our 'docker-push' script.
#
set -eux
# YYYY-MM-DD date, made available to all the config files, which can
# use it for tagging the docker images.
#
date=$(date +%F)
# Defaults
os="alpine"
force_tag="$date"
from="alpine:3.12.0"
user="user"
extra_packages=""
opam_switch="4.14.0"
opam_switch_options=""
opam_packages="dune utop"
docker_url="mjambon/ocaml:alpine"
# This is a bash array. Requires bash >= 4.4.
# Example:
#
# extra_docker_urls=("$docker_url-$date")
#
extra_docker_urls=()
# Each command line argument is a path to a config file.
configs=""
if [[ $# -gt 0 ]]; then
configs=$*
fi
build() {
(
if [[ -f "$config" ]]; then
echo "Build from config '$config'."
. ./"$config"
else
echo "Build with default settings."
fi
rm -rf tmp
mkdir -p tmp
mkdir -p tmp/os
cp -a src/os/"$os" tmp/os
cp -a src/opam tmp
cp -a src/create-dockerfile tmp
cp -a src/finalize tmp
extra_build_options=()
for url in "${extra_docker_urls[@]}"; do
extra_build_options+=( -t "$url" )
done
(
cd tmp
./create-dockerfile -o Dockerfile \
--os "$os" \
--from "$from" \
--force-tag "$force_tag" \
--create-user "$user" \
--extra-packages "$extra_packages" \
--opam-packages "$opam_packages" \
--opam-switch "$opam_switch" \
--opam-switch-options "$opam_switch_options"
docker build -t "$docker_url" "${extra_build_options[@]}" .
# Sanity check.
docker run -t "$docker_url" opam exec -- ocamlc -v
)
echo "$docker_url" >> "$pushme"
for url in "${extra_docker_urls[@]}"; do
echo "$url" >> "$pushme"
done
)
}
pushme=pushme
rm -f "$pushme"
for config in $configs; do
build
done