Build and Deploy
To properly build the executor you can define a build phase using a specific maven plugin. The following configuration must be placed in pom.xml
file.
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>[MVN_JAR_PLUGIN_VERSION]</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>[ME_ID]</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Container Build
To deploy a micro-executor you can create the Docker image.
Below is an example of a file that you can adapt to suit your build requirements:
# start from amazon's OpenJDK distro
FROM amazoncorretto:11
# install user management utils
RUN yum -y install shadow-utils
# JAR location - default is in target directory
# JARPATH can be both a local directory or a remote URL
ARG JARPATH=target/*.jar
# create kokos group
RUN groupadd -g 1000 kokos
# create kokos user
RUN useradd -u 1000 -g 1000 --system --create-home -s /bin/false kokos
# copy local JAR or download remote JAR into working dir
ADD $JARPATH /home/kokos/[JAR_NAME].jar
# set working dir
WORKDIR /home/kokos
# create kokos base directory
RUN mkdir -p /home/kokos/etc/kokos
# set working dir permissions
RUN chown -R kokos:kokos /home/kokos
# run container as user kokos
USER kokos
# start application
CMD "java" "-cp" "[JAR_NAME].jar" "[PACKAGE_MAIN_CLASS]"
Now you can execute: docker build -t [ME_ID] .
When the image is created you can deploy it to AWS ECR. The prerequisites are:
- Smeup AWS user (ask to Smeup LAB)
- AWS CLI configured locally
- ECR repository
# Docker login with ECR
aws ecr get-login-password --region eu-south-1 | docker login --username AWS --password-stdin 100076361442.dkr.ecr.eu-south-1.amazonaws.com
# Docker tag image with ECR
docker tag [ECR_REPO_NAME] 100076361442.dkr.ecr.eu-south-1.amazonaws.com/[ECR_REPO_NAME]:[IMAGE_TAG]
# Docker push to ECR
docker push 100076361442.dkr.ecr.eu-south-1.amazonaws.com/[ECR_REPO_NAME]:[IMAGE_TAG]
The actual naming conventions for ECR_REPO_NAME
is kokos-[SDK_LANGUAGE]-[COMPANY]
. For example for the micro executor me-java-smeuplab
the EXR_REPO_NAME
is kokos-java-smeuplab
.
CI
You can directly build and push the container image using GitHub Actions.
Below an example of Java workflow:
# Build project and publish container image to AWS after each merged PR to develop
name: develop-release
on:
push:
branches:
- develop
env:
AWS_REGION: eu-south-1 # AWS region repo ECR (Milan)
ECR_REPOSITORY: [ECR_REPO_NAME]
jobs:
java-develop-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: "11"
distribution: "corretto"
- name: Prepare pom.xml
run: |
echo ${{ secrets.NEXUS_SETTINGS_XML_B64 }} | base64 -d > $HOME/settings.xml
echo "downloaded settings.xml on dir $HOME/settings.xml"
chmod 777 $HOME/settings.xml
echo "Maven version"
mvn --version
echo "Java version"
java --version
echo "Java home: $JAVA_HOME"
- name: Maven Build
run: |
mvn -s $HOME/settings.xml deploy -Dmaven.test.skip
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: latest
# by default the Dockerfile looks for the latest snapshot available, we use that
run: |
echo "building image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
To properly use the previous action you can save the following Github Action Secrets:
AWS_ACCESS_KEY_ID
: the access key of AWS Smeup accountAWS_SECRET_ACCESS_KEY
: the secret key of AWS Smeup accountNEXUS_SETTINGS_XML_B64
: the base64 of.m2/setting.xml
file to build jar with the mirror of Smeup nexus.