Skip to content

Building FASTEN Docker images

Mihhail Sokolov edited this page Dec 3, 2020 · 6 revisions

This page describes steps for building and running a Dockerized version of the FASTEN server with a particular FASTEN plug-in. In the end, an example of building and running OPAL plug-in is provided.

Instructions

  • First, clone the project into a folder of your interest:
git clone https://github.com/fasten-project/fasten
  • Build the project using Maven:
cd fasten && mvn clean install
  • Before building a Docker image, it's sometimes needed to check out whether the Docker image exists. It may also be needed to delete a previous Docker image. Hence use the following command to find the Docker image you are looking for:
docker images | grep fasten

Note that the name of all the Docker images of the FASTEN project starts the prefix fasten.*.

  • If needed, use the following command to remove a previous Docker image:
docker rmi -f $IMAGE_NAME

Replace the $IMAGE_NAME with the name of the Docker image of your interest. Note that if you are building a particular plug-in again, you need to remove the plug-in's previous Docker image or give its Docker image a new name in the next step.

Execute the following command inside the docker folder to build a Docker image:

docker build -t fasten.server.$NAME -f server/Dockerfile .

Replace the $NAME with the name of your plug-in. A short and descriptive name is recommended.

  • To run the Dockerized version of the FASTEN server with the plug-in of your interest, run the following command:
docker run --user $(id -u):$(id -g) --network="host" -d fasten.server.$NAME -pl $PLUGIN

Replace fasten.server.$NAME with the name you specified in the previous step, and $PLUGIN with the name of the plugin you want to run (you can specify multiple plugins by separating them with "," or using -pl flag multiple times. Also, note that if you would like to change the default Kafka topic of the plug-in or pass DB credentials, check out the guide here.

  • To check the status of the Docker container that you have launched, execute the following command:
docker ps -a | grep "fasten.server.$NAME"

Again, replace fasten.server.$NAME with the name of your Docker image. The command shows the container ID and status of your own Docker image.

  • At times, it's needed to check out the logs of the instance of the FASTEN server that you've launched. To do so, run below command:
docker logs $CONTAINER_ID

Replace $CONTAINER_ID with the container ID of your own Docker image, which is obtained in the previous step.

Example

This is an example of building and running OPAL plug-in within a Dockerized version of the FASTEN server:

git clone https://github.com/fasten-project/fasten
cd fasten && mvn clean install
docker rmi -f fasten.server.opal
cd docker
docker build -t fasten.server.opal -f server/Dockerfile .
docker run --user $(id -u):$(id -g) --network="host" -d fasten.server.opal -pl OPAL
docker ps -a | grep "fasten.server.opal"

Using GitHub packages to pull FASTEN images

  1. Generate a GitHub personal access token (aka $GITHUB_TOKEN). You need to specify the repo and read:packages scopes

  2. Try to login docker to the FASTEN pkg registry. Instructions from here.

echo $GITHUB_TOKEN | docker login https://docker.pkg.github.com -u fasten --password-stdin

docker pull docker.pkg.github.com/fasten-project/fasten/fasten.server:latest

docker run docker.pkg.github.com/fasten-project/fasten/fasten.server:latest --help

If this works, we can then try configuring K8S manifests.

  1. Create a Kubernetes secret with login credentials for the FASTEN Docker registry
kubectl create secret docker-registry fasten.docker.registry --namespace=fasten --docker-server=https://docker.pkg.github.com --docker-username=fasten --docker-password=$GITHUB_TOKEN
  1. Create a simple deployment (simple.yaml) like the following
apiVersion: v1
kind: Pod
metadata:
  name: fasten-server
spec:
  containers:
  - name: fasten-server
    image: docker.pkg.github.com/fasten-project/fasten/fasten.server:latest
  imagePullSecrets:
  - name: fasten.docker.registry

and apply it on the fasten namespace

kubectl apply --namespace=fasten -f simple.yaml

This will just run a pod and exit, but it demonstrates how to use the GitHub Package Registry in Kubernetes.

Deploying REST API in Docker

In order to deploy the REST API in the Docker container follow the next steps:

  1. First checkout the kbapi branch
  2. Then build the JAR of the REST API
cd analyzer/rest-api && mvn clean install spring-boot:repackage
  1. Build the Docker image
docker build -t fasten.restapi .
  1. Run the Docker image
docker run -e "FASTEN_DBPASS=fasten" --network='host' -d fasten.restapi

To check the result, you can run the following command that will return the package version record from the metadata database for junit:junit:4.12:

curl localhost:8080/mvn/packages/junit:junit/4.12