From 8353244f2cecce5fe3c8276801988169c6593f05 Mon Sep 17 00:00:00 2001 From: Sergei Azovskov Date: Tue, 30 Jun 2020 23:51:13 +0100 Subject: [PATCH 1/5] Add generic platform --- dockerfiles/generic/Dockerfile | 29 ++++++++++++++++++++++++++++ dockerfiles/generic/README.md | 22 +++++++++++++++++++++ dockerfiles/generic/build.sh | 16 +++++++++++++++ dockerfiles/generic/prepare_build.sh | 20 +++++++++++++++++++ dockerfiles/generic/run.sh | 6 ++++++ 5 files changed, 93 insertions(+) create mode 100644 dockerfiles/generic/Dockerfile create mode 100644 dockerfiles/generic/README.md create mode 100644 dockerfiles/generic/build.sh create mode 100644 dockerfiles/generic/prepare_build.sh create mode 100644 dockerfiles/generic/run.sh diff --git a/dockerfiles/generic/Dockerfile b/dockerfiles/generic/Dockerfile new file mode 100644 index 0000000..a274cea --- /dev/null +++ b/dockerfiles/generic/Dockerfile @@ -0,0 +1,29 @@ +# using ubuntu as distro having a better set of defaults and packages +# using 20:04 as it's latest at the moment (June 2020) +# not using latest explicitly to make it future proof +FROM ubuntu:20.04 + +# Install locales and set UTF-8 as default locale to avoid common pitfails +# Install build-essential and openssl-dev as a minimum set of shared libs and headers +# This is required to build and link any other language executable + +RUN apt-get update && apt-get install -y locales \ + build-essential openssl libssl-dev ca-certificates \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +ENV LANG en_US.utf8 + +WORKDIR /source + +COPY ./prepare_build.sh . +RUN /bin/bash /source/prepare_build.sh + +COPY . . + +# Note this depends on the entire repository content +# Build sh might contents and even create `run.sh` +RUN /bin/bash /source/build.sh + +# Use /bin/bash to avoid issues with +x +ENTRYPOINT ["/bin/bash", "/source/run.sh"] diff --git a/dockerfiles/generic/README.md b/dockerfiles/generic/README.md new file mode 100644 index 0000000..3dc55d1 --- /dev/null +++ b/dockerfiles/generic/README.md @@ -0,0 +1,22 @@ +# Customizable platform based on ubuntu:latest + +## How to use generic platform: + +1. Place your dependencies in `prepare_buld.sh` (you can skip it) +2. Place you build logic into `build.sh` (you can skip it) +3. Launch your code in `run.sh` (code will be located at `/source/`) + + +## Build algorithm: + +* a single file `./prepare_buld.sh` copied under `container:/source/prepare_buld.sh` +* `/source/prepare_buld.sh` is launched before the build step to setup dependencies and caches +* all code from the repository is placed under `container:/source/` folder +* `/source/buld.sh` will be called at the build step +* `/source/run.sh` will be called as an entry point for your solution + +### Notes: + +* `/source/run.sh` might be generated or modified by `build.sh` +* `prepare_buld.sh` must not depend on any other file in the repository +* `prepare_buld.sh` should be used for installing packages and getting extra dependencies, it should not change too frequently and required to make builds faster diff --git a/dockerfiles/generic/build.sh b/dockerfiles/generic/build.sh new file mode 100644 index 0000000..98cee69 --- /dev/null +++ b/dockerfiles/generic/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e # do not proceed if we failed somewhere + +# Replace contents with anything you need to do on the build step +# Here you can access internet and install additional packages with apt-get install +# You can also compile you application and place all the needed data where you expect it + +# Note: if you install packages with apt-get don't forget to run +# apt-get clean && rm -rf /var/lib/apt/lists/* +# or you might end up in weird caching issues + + +mkdir -p /data +echo "Hello, World!" > /data/greeting.txt + diff --git a/dockerfiles/generic/prepare_build.sh b/dockerfiles/generic/prepare_build.sh new file mode 100644 index 0000000..7f6fd6d --- /dev/null +++ b/dockerfiles/generic/prepare_build.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e # do not proceed if we failed somewhere + +# Replace contents with anything you need to do BEFORE the build step +# This is the best place to download any external dependency and install additional packages + +# Note: if you install packages with apt-get don't forget to run +# `apt-get clean && rm -rf /var/lib/apt/lists/*` +# or you might end up in weird caching issues + +# Note: this must be a self-contained file and should not depent on any other file in your repo + +# Note: all the same can be done in build.sh, this file purely exists to speed-up build times +# and help orgamizer's team with possible cache issues +# Please be kind and move as much as possible here (and don't change it too often) + + +apt-get install less # just a small package to make an example +apt-get clean && rm -rf /var/lib/apt/lists/* diff --git a/dockerfiles/generic/run.sh b/dockerfiles/generic/run.sh new file mode 100644 index 0000000..556e7b6 --- /dev/null +++ b/dockerfiles/generic/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Just replace contents with +# exec $your_binary $your_extra_flags $@ + +exec /bin/echo `cat /data/greeting.txt` and $@ From 9d519f15d938cc64b69b2d43613f01b7f79db1e1 Mon Sep 17 00:00:00 2001 From: Sergei Azovskov Date: Tue, 30 Jun 2020 23:57:50 +0100 Subject: [PATCH 2/5] replace a bad package in prepare_build.sh with an example --- dockerfiles/generic/prepare_build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dockerfiles/generic/prepare_build.sh b/dockerfiles/generic/prepare_build.sh index 7f6fd6d..5fa89db 100644 --- a/dockerfiles/generic/prepare_build.sh +++ b/dockerfiles/generic/prepare_build.sh @@ -16,5 +16,7 @@ set -e # do not proceed if we failed somewhere # Please be kind and move as much as possible here (and don't change it too often) -apt-get install less # just a small package to make an example +# Uncomment the following line and put some packages there +# apt-get install + apt-get clean && rm -rf /var/lib/apt/lists/* From 3eee31965f297d87ccb6704dbfed0def3ca827b3 Mon Sep 17 00:00:00 2001 From: Sergei Azovskov Date: Wed, 1 Jul 2020 00:12:02 +0100 Subject: [PATCH 3/5] fixed spelling in comments --- dockerfiles/generic/Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dockerfiles/generic/Dockerfile b/dockerfiles/generic/Dockerfile index a274cea..75adee2 100644 --- a/dockerfiles/generic/Dockerfile +++ b/dockerfiles/generic/Dockerfile @@ -1,11 +1,11 @@ -# using ubuntu as distro having a better set of defaults and packages +# using ubuntu as distro which has a better set of defaults and packages # using 20:04 as it's latest at the moment (June 2020) # not using latest explicitly to make it future proof FROM ubuntu:20.04 # Install locales and set UTF-8 as default locale to avoid common pitfails # Install build-essential and openssl-dev as a minimum set of shared libs and headers -# This is required to build and link any other language executable +# This is effectively required to build and link any other language executable RUN apt-get update && apt-get install -y locales \ build-essential openssl libssl-dev ca-certificates \ @@ -21,8 +21,7 @@ RUN /bin/bash /source/prepare_build.sh COPY . . -# Note this depends on the entire repository content -# Build sh might contents and even create `run.sh` +# build.sh might generate `run.sh` RUN /bin/bash /source/build.sh # Use /bin/bash to avoid issues with +x From d956a0a40da8800e6b6632c5263b8b11656f4890 Mon Sep 17 00:00:00 2001 From: Sergei Azovskov Date: Wed, 1 Jul 2020 01:21:34 +0100 Subject: [PATCH 4/5] add proper quoting for $@ --- dockerfiles/generic/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dockerfiles/generic/run.sh b/dockerfiles/generic/run.sh index 556e7b6..faef202 100644 --- a/dockerfiles/generic/run.sh +++ b/dockerfiles/generic/run.sh @@ -1,6 +1,6 @@ #!/bin/bash # Just replace contents with -# exec $your_binary $your_extra_flags $@ +# exec $your_binary $your_extra_flags "$@" -exec /bin/echo `cat /data/greeting.txt` and $@ +exec /bin/echo `cat /data/greeting.txt` and "$@" From 48820e0b6109332aca4bb573315fb1f7c4e18c0c Mon Sep 17 00:00:00 2001 From: Sergei Azovskov Date: Wed, 1 Jul 2020 13:45:07 +0100 Subject: [PATCH 5/5] fix typos in README and comments --- dockerfiles/generic/README.md | 12 ++++++------ dockerfiles/generic/prepare_build.sh | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dockerfiles/generic/README.md b/dockerfiles/generic/README.md index 3dc55d1..7c2b8bc 100644 --- a/dockerfiles/generic/README.md +++ b/dockerfiles/generic/README.md @@ -2,21 +2,21 @@ ## How to use generic platform: -1. Place your dependencies in `prepare_buld.sh` (you can skip it) +1. Place your dependencies in `prepare_build.sh` (you can skip it) 2. Place you build logic into `build.sh` (you can skip it) 3. Launch your code in `run.sh` (code will be located at `/source/`) ## Build algorithm: -* a single file `./prepare_buld.sh` copied under `container:/source/prepare_buld.sh` -* `/source/prepare_buld.sh` is launched before the build step to setup dependencies and caches +* a single file `./prepare_build.sh` copied under `container:/source/prepare_build.sh` +* `/source/prepare_build.sh` is launched before the build step to setup dependencies and caches * all code from the repository is placed under `container:/source/` folder -* `/source/buld.sh` will be called at the build step +* `/source/build.sh` will be called at the build step * `/source/run.sh` will be called as an entry point for your solution ### Notes: * `/source/run.sh` might be generated or modified by `build.sh` -* `prepare_buld.sh` must not depend on any other file in the repository -* `prepare_buld.sh` should be used for installing packages and getting extra dependencies, it should not change too frequently and required to make builds faster +* `prepare_build.sh` must not depend on any other file in the repository +* `prepare_build.sh` should be used for installing packages and getting extra dependencies, it should not change too frequently and required to make builds faster diff --git a/dockerfiles/generic/prepare_build.sh b/dockerfiles/generic/prepare_build.sh index 5fa89db..555804f 100644 --- a/dockerfiles/generic/prepare_build.sh +++ b/dockerfiles/generic/prepare_build.sh @@ -9,10 +9,10 @@ set -e # do not proceed if we failed somewhere # `apt-get clean && rm -rf /var/lib/apt/lists/*` # or you might end up in weird caching issues -# Note: this must be a self-contained file and should not depent on any other file in your repo +# Note: this must be a self-contained file and should not depend on any other file in your repo # Note: all the same can be done in build.sh, this file purely exists to speed-up build times -# and help orgamizer's team with possible cache issues +# and help organizer's team with possible cache issues # Please be kind and move as much as possible here (and don't change it too often)