ec2_post_init
Populate STScI EC2 instances with ease
ec2pinit.inc.sh
Go to the documentation of this file.
1## @file
2## @brief Framework entrypoint
3##
4## Include this file in your script to use ec2pinit's functions
5##
6## @mainpage
7## @section intro_sec Introduction
8##
9## This shell library is useful if you are not a systems administrator but want to spin up an EC2 image to do data analysis or research. ec2_post_init provides a simple easy to use API that can:
10##
11## - Install system software (see: ``system.inc.sh :: sys_pkg_install()``)
12## - Install Docker (see: ``docker.inc.sh :: docker_setup()``)
13## - Install Miniconda3 (see: ``miniconda.inc.sh :: mc_install()``)
14## - Install STScI pipelines (see: ``astroconda.inc.sh``)
15## - ``ac_releases_install_hst()``
16## - ``ac_releases_install_jwst()``
17## - ``ac_releases_install_data_analysis()``
18##
19## @section require_sec Supported Operating Systems
20##
21## - Red Hat
22## - CentOS 7+
23## - Fedora 19+
24## - Debian
25## - Stretch+
26## - Ubuntu
27## - Bionic+
28##
29## @section install_sec Installing
30##
31## @subsection install_system_subsec System installation
32##
33## @code{.sh}
34## git clone https://github.com/spacetelescope/ec2_post_init
35## cd ec2_post_init
36## sudo make install PREFIX=/usr/local
37## @endcode
38##
39## @subsection install_portable_subsec Portable installation
40##
41## If you don't want to install ec2_post_init permanently, you don't have to. This is especially useful for systems that provide ``curl`` and ``tar`` by default but lack ``git`` and ``make``. Here is how to use ec2_post_init from its source directory:
42##
43## @code{.sh}
44## curl https://github.com/spacetelescope/ec2_post_init/archive/refs/heads/main.tar.gz | tar -x
45## cd ec2_post_init
46## export PATH=$(pwd)/bin:$PATH
47## @endcode
48##
49## @section usage_sec Using ec2_post_init
50##
51## Now you can include the library in your own script by sourcing ``ec2pinit.inc.sh``...
52##
53## @code{.sh}
54## #!/usr/bin/env bash
55##
56## # Load ec2_post_init
57## source ec2pinit.inc.sh
58##
59## # ...
60## @endcode
61##
62## To see how one can use ec2_post_init to populate a system with Miniconda3 and the three major STScI pipeline releases, please refer to the @ref full_example_page page. The API reference for each library module can be found <a href="files.html">here</a>.
63##
64## @section install_develop_sec Developing
65##
66## To write code for ec2_post_init you should have access to an EC2 instance, or a host with ``docker`` or ``vagrant`` installed.
67##
68## @code{.sh}
69## git clone https://github.com/spacetelescope/ec2_post_init
70## cd ec2_post_init
71## export PATH=$(pwd)/bin:$PATH
72## @endcode
73##
74## To test ec2_post_init using docker:
75##
76## @code{.sh}
77## docker run --rm -it -v $(pwd):/data -w /data centos:7 /bin/bash
78## [root@abc123 data]# export PATH=$PATH:/data/bin
79## [root@abc123 data]# cd tests
80## [root@abc123 tests]# ./run_tests.sh
81## @endcode
82##
83## To test ec2_post_init using vagrant (VirtualBox):
84##
85## @code{.sh}
86## mkdir -p ~/vagrant/centos/7
87## cd ~/vagrant/centos/7
88## @endcode
89##
90## Create a new ``Vagrantfile``. Be sure to change any paths to match your local system
91##
92## @code
93## Vagrant.configure("2") do |config|
94## config.vm.box = "generic/centos7"
95##
96## # Mount the ec2_post_init source directory at /data inside of the VM
97## config.vm.synced_folder "/home/example/my_code/ec2_post_init", "/data"
98##
99## # Change VM resources
100## config.vm.provider "virtualbox" do |v|
101## v.memory = 2048
102## v.cpus = 2
103## end
104## end
105## @endcode
106##
107## Provision the VM, log in, and execute the test suite:
108##
109## @code{.sh}
110## vagrant up
111## vagrant ssh sudo -i
112## [root@vagrant123 ~]# export PATH=$PATH:/data/bin
113## [root@vagrant123 data]# cd /data/tests
114## [root@vagrant123 tests]# ./run_tests.sh
115## @endcode
116##
117## @page full_example_page Full example
118## @include cumulative.sh
119##
120## @page license_page License
121## @include LICENSE.txt
122
123(( $EC2PINIT_INCLUDED )) && return
124EC2PINIT_INCLUDED=1
125
126## @property ec2pinit_root
127## @brief Path to ec2pinit directory
128##
129## Do not change this value
130ec2pinit_root="$(readlink -f $(dirname ${BASH_SOURCE[0]})/..)"
132
133## @property ec2pinit_framework
134## @brief Path to framework directory
135##
136## Do not change this value
137ec2pinit_framework="$ec2pinit_root"/framework
138
139# Adjust the framework path when we're installed as a system package
140if [ ! -d "$ec2pinit_framework" ]; then
141 ec2pinit_framework="$ec2pinit_root/share/ec2_post_init"/framework
142fi
144
145## @property ec2pinit_tempdir
146## @brief Where ec2pinit will store temporary data
147##
148## Do not change this value
149ec2pinit_tempdir=/tmp/ec2_post_init
151
152## FLAG - Print info messages
153DEBUG_INFO=$(( 1 << 1 ))
155
156## FLAG - Print warning messages
157DEBUG_WARN=$(( 1 << 2 ))
159
160## FLAG - Print error messages
161DEBUG_ERROR=$(( 1 << 3 ))
163
164## FLAG - Print only warnings and errors
167
168## FLAG - Print all messages
171
172## @property ec2pinit_debug
173## @brief Debug output control
174##
175## Set print statement behavior with: ``DEBUG_INFO``, ``DEBUG_WARN``, and ``DEBUG_ERROR``
176## @code{.sh}
177## ec2pinit_debug=$(( DEBUG_WARN | DEBUG_ERROR ))
178## @endcode
179ec2pinit_debug=${ec2pinit_debug:-$DEBUG_DEFAULT}
181
182# If the user modifies debug flags through the environment
183# verify an integer was received. If not then use the defaults
184if ! [[ "$ec2pinit_debug" =~ [0-9]+ ]]; then
185 # pre-IO function availability
186 echo "WARN: ec2pinit_debug: Must be a positive integer!" >&2
187 echo "WARN: Using DEBUG_DEFAULT ($DEBUG_DEFAULT)." >&2
188 ec2pinit_debug=$DEBUG_DEFAULT
189fi
190
191bug_report() {
192 io_error "$*"
193 io_error "Please open an issue at: https://github.com/spacetelescope/ec2_post_init"
194 echo
195 echo TYPE
196 echo ====
197 ([ -f /.dockerenv ] && echo Docker) || echo 'Physical / Virtualized'
198 echo
199 echo KERNEL
200 echo ======
201 uname -a
202 echo
203 echo MEMORY
204 echo ======
205 command free -m
206 echo
207 echo CPU
208 echo ===
209 lscpu
210 echo
211 echo EC2_POST_INIT INFO
212 echo ==================
213 set | grep -E '^(ec2pinit|EC2PINIT|ec2_post_init|HAVE_|HOME|USER|PWD|sys_manager_)' | sort
214 echo
215 echo
216}
217
218mkdir -p "$ec2pinit_tempdir"
219source $ec2pinit_framework/io.inc.sh
220source $ec2pinit_framework/system.inc.sh
221
222# OS detection gate
223if (( ! HAVE_SUPPORT )); then
224 bug_report "OPERATING SYSTEM IS NOT SUPPORTED"
225 return 1
226else
227 if ! sys_initialize; then
228 bug_report "UNABLE TO INITIALIZE BASE OPERATING SYSTEM PACKAGES"
229 return 1
230 fi
231fi
232
233source $ec2pinit_framework/miniconda.inc.sh
234source $ec2pinit_framework/astroconda.inc.sh
235source $ec2pinit_framework/docker.inc.sh
236
237# Ensure any external success checks succeed
238true
239return
io_error(...)
Print an error message.
Definition: io.inc.sh:59
sys_initialize()
Install dependencies required by ec2_post_init
Definition: system.inc.sh:325
Exported String HAVE_SUPPORT
System is supported.
Definition: system.inc.sh:33
Exported String ec2pinit_tempdir
Where ec2pinit will store temporary data.
Exported String DEBUG_WARN
FLAG - Print warning messages.
Exported String ec2pinit_root
Path to ec2pinit directory.
Exported String ec2pinit_framework
Path to framework directory.
Exported String DEBUG_ALL
FLAG - Print all messages.
Exported String ec2pinit_debug
Debug output control.
Exported String DEBUG_DEFAULT
FLAG - Print only warnings and errors.
Exported String DEBUG_ERROR
FLAG - Print error messages.
Exported String DEBUG_INFO
FLAG - Print info messages.