diff --git a/dockerfiles/generic/Dockerfile b/dockerfiles/generic/Dockerfile new file mode 100644 index 0000000..75adee2 --- /dev/null +++ b/dockerfiles/generic/Dockerfile @@ -0,0 +1,28 @@ +# 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 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 \ + && 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 . . + +# build.sh might generate `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..7c2b8bc --- /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_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_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/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_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/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..555804f --- /dev/null +++ b/dockerfiles/generic/prepare_build.sh @@ -0,0 +1,22 @@ +#!/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 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 organizer's team with possible cache issues +# Please be kind and move as much as possible here (and don't change it too often) + + +# Uncomment the following line and put some packages there +# apt-get install + +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..faef202 --- /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 "$@"