Skip to content

Commit

Permalink
Docker container builder/publish for Airlift
Browse files Browse the repository at this point in the history
See airbase-docker/README.md for details
  • Loading branch information
Randgalt committed Aug 6, 2021
1 parent 7860e81 commit fddc834
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 0 deletions.
27 changes: 27 additions & 0 deletions airbase-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Airlift Docker Builder

For modules that contain a file named `.build-airlift-docker`,
the Maven properties below are used to generate a docker image during the
package phase and to deploy/push that image during the delpoy phase. This
[docker file](../airbase-docker/src/main/resources/AirliftDockerfile) is
used to build the image.

Note: modules must also contain `.build-airlift` so that the Airlift
launcher tarball is generated. The Maven build will fail if this file
is missing.

## Maven Properties

| Name | Default Value | Details |
| ----- | ------------- | ------- |
| air.docker.skip | false | skip all docker executions |
| air.docker.skip-build | false | skip docker build |
| air.docker.skip-deploy | false | skip docker deploy |
| air.docker.skip-tag | false | skip docker tagging |
| air.docker.verbose | false | enable verbose mode for dockerfile-maven-plugin |
| air.docker.repository | ${project.groupId}/${project.artifactId} | Docker repo image name |
| air.docker.application-name | ${project.artifactId} | `APPLICATION_NAME` in [AirliftDockerfile](../airbase-docker/src/main/resources/AirliftDockerfile) |
| air.docker.maintainer | ${project.groupId} | `MAINTAINER` in [AirliftDockerfile](../airbase-docker/src/main/resources/AirliftDockerfile) |
| air.docker.user | airlift | `USER` in [AirliftDockerfile](../airbase-docker/src/main/resources/AirliftDockerfile) |
| air.docker.jdk | openjdk:${project.build.targetJdk}-jdk | `JAVA_VERSION` in [AirliftDockerfile](../airbase-docker/src/main/resources/AirliftDockerfile) |
| air.docker.port | 8080 | `APPLICATION_PORT` in [AirliftDockerfile](../airbase-docker/src/main/resources/AirliftDockerfile) |
16 changes: 16 additions & 0 deletions airbase-docker/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.airlift</groupId>
<artifactId>airbase-root</artifactId>
<version>113-SNAPSHOT</version>
</parent>

<artifactId>airbase-docker</artifactId>

<description>Docker file for Airbase</description>
</project>
54 changes: 54 additions & 0 deletions airbase-docker/src/main/resources/AirliftDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
ARG ARTIFACT_ID
ARG ARTIFACT_VERSION
ARG APPLICATION_NAME
ARG JAVA_VERSION
ARG MAINTAINER
ARG USER
ARG APPLICATION_PORT

FROM alpine:3 as extractor

ARG ARTIFACT_ID
ARG ARTIFACT_VERSION
ARG APPLICATION_NAME
ARG JAVA_VERSION
ARG MAINTAINER
ARG USER
ARG APPLICATION_PORT

ADD ${ARTIFACT_ID}-${ARTIFACT_VERSION}.tar.gz /opt/${APPLICATION_NAME}
RUN ln -s "${ARTIFACT_ID}-${ARTIFACT_VERSION}" /opt/${APPLICATION_NAME}/${ARTIFACT_ID}

FROM ${JAVA_VERSION}

ARG ARTIFACT_ID
ARG ARTIFACT_VERSION
ARG APPLICATION_NAME
ARG JAVA_VERSION=11-jdk
ARG MAINTAINER
ARG USER
ARG APPLICATION_PORT

LABEL maintainer=${MAINTAINER}
LABEL service=${ARTIFACT_ID} version=${ARTIFACT_VERSION}

RUN apt-get update && \
apt-get install -y \
jq \
python \
tmux && \
rm -rf /var/lib/apt/lists/* && \
adduser --home /opt/${APPLICATION_NAME}/${ARTIFACT_ID} --no-create-home --disabled-login --gecos "" ${USER} && \
mkdir /var/log/${APPLICATION_NAME} && \
chown -R ${USER}:${USER} /var/log/${APPLICATION_NAME}

COPY --chown=${USER}:${USER} --from=extractor /opt/${APPLICATION_NAME} /opt/${APPLICATION_NAME}

EXPOSE ${APPLICATION_PORT}

ENV APPLICATION_NAME=${APPLICATION_NAME}
ENV ARTIFACT_ID=${ARTIFACT_ID}

CMD /opt/${APPLICATION_NAME}/${ARTIFACT_ID}/bin/launcher run \
--etc-dir=/etc/${APPLICATION_NAME} \
--verbose
128 changes: 128 additions & 0 deletions airbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1483,5 +1483,133 @@
</plugins>
</build>
</profile>

<!-- ======================================================================== -->
<!-- = = -->
<!-- = Build a docker image with the airlift launcher from a module if = -->
<!-- = .build-airlift-docker is present = -->
<!-- = = -->
<!-- ======================================================================== -->

<profile>
<id>build-airlift-docker</id>

<activation>
<file>
<exists>.build-airlift-docker</exists>
</file>
</activation>

<properties>
<air.docker.skip>false</air.docker.skip>
<air.docker.skip-build>${air.docker.skip}</air.docker.skip-build>
<air.docker.skip-deploy>${air.docker.skip}</air.docker.skip-deploy>
<air.docker.skip-tag>${air.docker.skip}</air.docker.skip-tag>
<air.docker.application-name>${project.artifactId}</air.docker.application-name>
<air.docker.maintainer>${project.groupId}</air.docker.maintainer>
<air.docker.user>airlift</air.docker.user>
<air.docker.jdk>openjdk:${project.build.targetJdk}-jdk</air.docker.jdk>
<air.docker.port>8080</air.docker.port>
<air.docker.repository>${project.groupId}/${project.artifactId}</air.docker.repository>
<air.docker.verbose>false</air.docker.verbose>
</properties>

<dependencies>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>airbase-docker</artifactId>
<version>113-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules combine.children="append">
<requireFilesExist>
<files>
<file>.build-airlift</file>
</files>
<message>A .build-airlift file is required to build the launcher tarball.</message>
</requireFilesExist>
<requireFilesExist>
<files>
<file>${project.build.directory}/${project.artifactId}-${project.version}.tar.gz</file>
</files>
<message>Airlift launcher tarball wasn't built</message>
</requireFilesExist>
</rules>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>airlift-docker</id>
<phase>validate</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<includeGroupIds>io.airlift</includeGroupIds>
<includeArtifactIds>airbase-docker</includeArtifactIds>
<excludes>META-INF/**</excludes>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId> <!-- this plugin is stable but no longer maintained - consider something else for the future -->
<version>1.4.13</version>
<executions>
<execution>
<id>docker</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<skipBuild>${air.docker.skip-build}</skipBuild>
<skipPush>${air.docker.skip-deploy}</skipPush>
<skipTag>${air.docker.skip-tag}</skipTag>
<repository>${air.docker.repository}</repository>
<tag>${project.version}</tag>
<contextDirectory>${project.build.directory}</contextDirectory>
<dockerfile>${project.build.directory}/AirliftDockerfile</dockerfile>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<verbose>${air.docker.verbose}</verbose>
<buildArgs>
<ARTIFACT_ID>${project.artifactId}</ARTIFACT_ID>
<ARTIFACT_VERSION>${project.version}</ARTIFACT_VERSION>
<APPLICATION_NAME>${air.docker.application-name}</APPLICATION_NAME>
<MAINTAINER>${air.docker.maintainer}</MAINTAINER>
<USER>${air.docker.user}</USER>
<JAVA_VERSION>${air.docker.jdk}</JAVA_VERSION>
<APPLICATION_PORT>${air.docker.port}</APPLICATION_PORT>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<modules>
<module>airbase</module>
<module>airbase-policy</module>
<module>airbase-docker</module>
</modules>

<build>
Expand Down

0 comments on commit fddc834

Please sign in to comment.