-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build Dockerfile from templates for multi-arch support.
- Loading branch information
Showing
11 changed files
with
302 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include paradrop/core/container/templates/Dockerfile-*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
paradrop/daemon/paradrop/core/container/templates/Dockerfile-go.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM {image} | ||
|
||
# Set up an unprivileged user so that we can drop out of root. | ||
# Make /home/paradrop so that npm can drop some files in there. | ||
# Make /opt/paradrop/app for installing the app files. | ||
RUN useradd --system --uid 999 paradrop && \ | ||
mkdir -p /home/paradrop && \ | ||
chown paradrop /home/paradrop && \ | ||
mkdir -p /opt/paradrop/app && \ | ||
chown paradrop /opt/paradrop/app && \ | ||
chmod a+s /opt/paradrop/app | ||
|
||
WORKDIR /opt/paradrop/app | ||
|
||
# Add cap_net_bind_service to node so that it can bind to ports 1-1024. | ||
# Not all images support this. | ||
RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/node || true | ||
|
||
{has_packages:if:RUN apt-get install -y {packages}} | ||
|
||
# Defang setuid/setgid binaries. | ||
RUN find / -perm +6000 -type f -exec chmod a-s {{}} \; || true | ||
|
||
ENV GOPATH=/opt/paradrop/go | ||
|
||
# Now copy the files. | ||
COPY . /opt/paradrop/app/ | ||
RUN chown paradrop:paradrop -R /opt/paradrop/app | ||
|
||
RUN go get -d && \ | ||
go build && \ | ||
cp app /usr/local/bin/ | ||
|
||
{drop_root:if:USER paradrop} | ||
|
||
CMD {cmd} |
38 changes: 38 additions & 0 deletions
38
paradrop/daemon/paradrop/core/container/templates/Dockerfile-gradle.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
FROM {image} | ||
|
||
USER root | ||
|
||
# Set up an unprivileged user so that we can drop out of root. | ||
# Make /home/paradrop so that npm can drop some files in there. | ||
# Make /opt/paradrop/app for installing the app files. | ||
RUN useradd --system --uid 999 paradrop && \ | ||
mkdir -p /home/paradrop && \ | ||
chown paradrop /home/paradrop && \ | ||
mkdir -p /opt/paradrop/app && \ | ||
chown paradrop /opt/paradrop/app && \ | ||
chmod a+s /opt/paradrop/app | ||
|
||
WORKDIR /opt/paradrop/app | ||
|
||
# Add cap_net_bind_service to node so that it can bind to ports 1-1024. | ||
# Not all images support this. | ||
RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/node || true | ||
|
||
{has_packages:if:RUN apt-get install -y {packages}} | ||
|
||
# Defang setuid/setgid binaries. | ||
RUN find / -perm +6000 -type f -exec chmod a-s {{}} \; || true | ||
|
||
# The default directory (/root/.m2) is not writable by paradrop user. | ||
# The logger option makes maven a little less verbose. | ||
ENV MAVEN_CONFIG=/opt/paradrop/.m2 \ | ||
MAVEN_OPTS="-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn" | ||
|
||
# Now copy the files. | ||
COPY . /opt/paradrop/app/ | ||
RUN if [ -f build.gradle ]; then gradle build --no-daemon; fi | ||
RUN chown paradrop:paradrop -R /opt/paradrop/app | ||
|
||
{drop_root:if:USER paradrop} | ||
|
||
CMD {cmd} |
41 changes: 41 additions & 0 deletions
41
paradrop/daemon/paradrop/core/container/templates/Dockerfile-maven.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM {image} | ||
|
||
# Set up an unprivileged user so that we can drop out of root. | ||
# Make /home/paradrop so that npm can drop some files in there. | ||
# Make /opt/paradrop/app for installing the app files. | ||
RUN useradd --system --uid 999 paradrop && \ | ||
mkdir -p /home/paradrop && \ | ||
chown paradrop /home/paradrop && \ | ||
mkdir -p /opt/paradrop/app && \ | ||
chown paradrop /opt/paradrop/app && \ | ||
chmod a+s /opt/paradrop/app | ||
|
||
WORKDIR /opt/paradrop/app | ||
|
||
# Add cap_net_bind_service to node so that it can bind to ports 1-1024. | ||
# Not all images support this. | ||
RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/node || true | ||
|
||
{has_packages:if:RUN apt-get install -y {packages}} | ||
|
||
# Defang setuid/setgid binaries. | ||
RUN find / -perm +6000 -type f -exec chmod a-s {{}} \; || true | ||
|
||
# The default directory (/root/.m2) is not writable by paradrop user. | ||
# The logger option makes maven a little less verbose. | ||
ENV MAVEN_CONFIG=/opt/paradrop/.m2 \ | ||
MAVEN_OPTS="-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dmaven.test.skip=true" | ||
|
||
# Copy paradrop.yaml and pom.xml, the latter only if it exists. These | ||
# layers will be cached as long as the requirements do not change. | ||
COPY paradrop.yaml pom.xm[l] /opt/paradrop/app/ | ||
RUN if [ -f pom.xml ]; then mvn --batch-mode dependency:resolve; fi | ||
|
||
# Now copy the files. | ||
COPY . /opt/paradrop/app/ | ||
RUN mvn --batch-mode package | ||
RUN chown paradrop:paradrop -R /opt/paradrop/app | ||
|
||
{drop_root:if:USER paradrop} | ||
|
||
CMD {cmd} |
41 changes: 41 additions & 0 deletions
41
paradrop/daemon/paradrop/core/container/templates/Dockerfile-node.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM {image} | ||
|
||
ENV npm_config_loglevel=warn | ||
|
||
# Set up an unprivileged user so that we can drop out of root. | ||
# Make /home/paradrop so that npm can drop some files in there. | ||
# Make /opt/paradrop/app for installing the app files. | ||
RUN useradd --system --uid 999 paradrop && \ | ||
mkdir -p /home/paradrop && \ | ||
chown paradrop /home/paradrop && \ | ||
mkdir -p /opt/paradrop/app && \ | ||
chown paradrop /opt/paradrop/app && \ | ||
chmod a+s /opt/paradrop/app | ||
|
||
WORKDIR /opt/paradrop/app | ||
|
||
# Add cap_net_bind_service to node so that it can bind to ports 1-1024. | ||
# Not all images support this. | ||
RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/node || true | ||
|
||
# Install popular tools here. | ||
RUN npm install --global gulp-cli | ||
|
||
{has_packages:if:RUN apt-get update && apt-get install -y {packages}} | ||
|
||
# Defang setuid/setgid binaries. | ||
RUN find / -perm +6000 -type f -exec chmod a-s {{}} \; || true | ||
|
||
# Copy paradrop.yaml and package.json, the latter only if it exists. Then call | ||
# init-app.sh to install dependencies. These layers will be cached as long as | ||
# the requirements do not change. | ||
COPY paradrop.yaml package.jso[n] /opt/paradrop/app/ | ||
RUN npm rebuild && \ | ||
if [ -f package.json ]; then npm install; fi | ||
|
||
COPY . /opt/paradrop/app/ | ||
RUN chown paradrop:paradrop -R /opt/paradrop/app | ||
|
||
{drop_root:if:USER paradrop} | ||
|
||
CMD {cmd} |
40 changes: 40 additions & 0 deletions
40
paradrop/daemon/paradrop/core/container/templates/Dockerfile-python2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM {image} | ||
|
||
# Set up an unprivileged user so that we can drop out of root. | ||
# Make /home/paradrop so that npm can drop some files in there. | ||
# Make /opt/paradrop/app for installing the app files. | ||
RUN useradd --system --uid 999 paradrop && \ | ||
mkdir -p /home/paradrop && \ | ||
chown paradrop /home/paradrop && \ | ||
mkdir -p /opt/paradrop/app && \ | ||
chown paradrop /opt/paradrop/app && \ | ||
chmod a+s /opt/paradrop/app | ||
|
||
WORKDIR /opt/paradrop/app | ||
|
||
# Add cap_net_bind_service to node so that it can bind to ports 1-1024. | ||
# Not all images support this. | ||
RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/node || true | ||
|
||
# Install some useful tools and libraries. | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
iptables | ||
|
||
{has_packages:if:RUN apt-get install -y {packages}} | ||
|
||
# Defang setuid/setgid binaries. | ||
RUN find / -perm +6000 -type f -exec chmod a-s {{}} \; || true | ||
|
||
# Copy paradrop.yaml and requirements.txt, the latter only if it exists. These | ||
# layers will be cached as long as the requirements do not change. | ||
COPY paradrop.yaml requirements.tx[t] /opt/paradrop/app/ | ||
RUN if [ -f requirements.txt ]; then pip install --requirement requirements.txt; fi | ||
|
||
# Now copy the rest of the files. | ||
COPY . /opt/paradrop/app/ | ||
RUN chown paradrop:paradrop -R /opt/paradrop/app | ||
|
||
{drop_root:if:USER paradrop} | ||
|
||
CMD {cmd} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import string | ||
|
||
|
||
class TemplateFormatter(string.Formatter): | ||
""" | ||
String formatter that supports method calls, loops, and conditionals. | ||
See: https://github.com/ebrehault/superformatter | ||
""" | ||
|
||
def format_field(self, value, spec): | ||
if spec.startswith('repeat'): | ||
template = spec.partition(':')[-1] | ||
if type(value) is dict: | ||
value = value.items() | ||
return ''.join([template.format(item=item) for item in value]) | ||
elif spec == 'call': | ||
return value() | ||
elif spec.startswith('if'): | ||
return (value and spec.partition(':')[-1]) or '' | ||
else: | ||
return super(TemplateFormatter, self).format_field(value, spec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters