Skip to content

Commit

Permalink
Creates docker containers for client lib and runner (#440)
Browse files Browse the repository at this point in the history
  - Creates docker containers for client and
     lib microservice.
  - Adds docker compose files for development
    and localhost installation.
  - Adds docker image publishing steps to
    Github Actions.
  • Loading branch information
nichlaes authored Jan 24, 2024
1 parent 105044c commit 0c79aec
Show file tree
Hide file tree
Showing 13 changed files with 456 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,33 @@ jobs:
with:
files: client/coverage/clover.xml
flags: client-unit-integration-tests

get_version:
name: Get version
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install jq
run: sudo apt-get install -y jq
- name: get version
id: get_version
run: |
version=`cat ./client/package.json | jq -r '.version'`
echo "version=$version" >> $GITHUB_OUTPUT
outputs:
version: ${{ steps.get_version.outputs.version }}

publish-docker-image:
if: |
github.event_name == 'push' &&
(startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/heads/release-v'))
name: Publish Docker image
needs: [client, get_version]
uses: ./.github/workflows/docker.yml
with:
registry: ghcr.io
image-name: into-cps-association/dtaas-client
version: ${{ needs.get_version.outputs.version }}
dockerfile: client.dockerfile
46 changes: 46 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Push Docker Image

on:
workflow_call:
inputs:
registry:
required: false
type: string
default: 'ghcr.io'
image-name:
required: true
type: string
version:
required: true
type: string
default: 'latest'
dockerfile:
required: true
type: string

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/${{ inputs.dockerfile }}
push: true
tags: ${{ inputs.registry }}/${{ inputs.image-name }}:${{ inputs.version }}
26 changes: 26 additions & 0 deletions .github/workflows/lib-ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,29 @@ jobs:
yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

get_version:
name: Get version
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install jq
run: sudo apt-get install -y jq
- name: get version
id: get_version
run: |
version=`cat ./client/package.json | jq -r '.version'`
echo "version=$version" >> $GITHUB_OUTPUT
outputs:
version: ${{ steps.get_version.outputs.version }}

publish-docker-image:
name: Publish Docker image
needs: [ publish-package, get_version]
uses: ./.github/workflows/docker.yml
with:
registry: ghcr.io
image-name: into-cps-association/dtaas-libms
version: ${{ needs.get_version.outputs.version }}
dockerfile: libms.dockerfile
3 changes: 3 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*/node_modules
*/build
*/test
48 changes: 48 additions & 0 deletions deploy/config/gateway/dynamic/fileConfig.docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
http:
routers:
dtaas:
entryPoints:
- http
rule: 'Host(`localhost`)'
middlewares:
- basic-auth
service: dtaas

user1:
entryPoints:
- http
rule: 'Host(`localhost`) && PathPrefix(`/user1`)'
middlewares:
- basic-auth
service: user1

libms:
entryPoints:
- http
rule: 'Host(`localhost`) && PathPrefix(`/lib`)'
service: libms


# Middleware: Basic authentication
middlewares:
basic-auth:
basicAuth:
usersFile: "/etc/traefik/auth"
removeHeader: true


services:
dtaas:
loadBalancer:
servers:
- url: "http://client:4000"

user1:
loadBalancer:
servers:
- url: "http://ml-workspace-user1:8080"

libms:
loadBalancer:
servers:
- url: "http://libms:4001"
20 changes: 20 additions & 0 deletions deploy/config/gateway/traefik.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
entryPoints:
http:
address: :80

providers:
providersThrottleDuration: 2s

# File provider for connecting things that are outside of docker / defining middleware
file:
filename: /etc/traefik/dynamic/fileConfig.yml
watch: true

# Enable traefik ui
#dapi:
# dashboard: true
# insecure: true

# Log level INFO|DEBUG|ERROR
log:
level: DEBUG
9 changes: 9 additions & 0 deletions deploy/config/lib.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT='4001'
MODE='local'
LOCAL_PATH ='/dtaas/libms/files'
GITLAB_GROUP ='dtaas'
GITLAB_URL='https://gitlab.com/api/graphql'
TOKEN='123-sample-token'
LOG_LEVEL='debug'
APOLLO_PATH='/lib'
GRAPHQL_PLAYGROUND='true'
106 changes: 106 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Docker workflow for DTaaS

This readme will explain the building and use of different docker files
for use in development and installation of the DTaaS software.

**NOTE**: A local docker and docker-compose installation is a pre-requisite
for using docker workflows.

## Folder Structure

There are two dockerfiles for building the containers:

- **client.dockerfile**: Dockerfile for building
the client application container.

- **libms.dockerfile**: Dockerfile for building the library microservice container.

There are also two compose files for development and local installation scenarios.

- **compose.dev.yml:** Docker Compose configuration for development environment.

- **compose.local.yml:** Docker Compose configuration for localhost installation.

## Build and Publish Docker Images

### Users

Build and publish the docker images. This step is required only for
the publication of images to Docker Hub. This publishing step is managed
only by project maintainers. Regular users can skip this step.

```sh
docker login -u <username> -p <password>
docker build -t intocps/libms:latest -f ./docker/libms.dockerfile .
docker tag intocps/libms:latest intocps/libms:version
docker push intocps/libms:latest
docker push intocps/libms:version

docker build -t intocps/dtaas-web:latest -f ./docker/client.dockerfile .
docker tag intocps/dtaas-web:latest intocps/dtaas-web:version
docker push intocps/dtaas-web:latest
docker push intocps/dtaas-web:version
```

To tag version 0.3.1 for example, use

```sh
docker tag intocps/dtaas-web:latest intocps/dtaas-web:0.3.1
```

### Developers

Use of docker images is handy for developers as well. It is suggested
that developers build the required images locally on their computer and
use them for development purposes. The images can be built using

```sh
docker-compose -f compose.dev.yml build
```

## Running Docker Containers

Follow these steps to use the application with docker.

The DTaaS application requires multiple configuration files. The list of
configuration files to be modified are given for each scenario.

### Development Environment

This scenario is for software developers:

The configuration files to be updated are:

1. client/config/dev.js
1. deploy/config/lib.docker
1. servers/config/gateway/auth

The relevant docker commands are:

```bash
docker-compose -f compose.dev.yml up -d #start the application
docker-compose -f compose.dev.yml down #terminate the application
```

### Localhost Use

This scenario is for users interested in using the software on
their computers (localhost):

The configuration files to be updated are:

1. deploy/config/client/env.local.js
1. deploy/config/lib.docker
1. deploy/config/gateway/auth

The relevant docker commands are:

```bash
docker-compose -f compose.local.yml up -d #start the application
docker-compose -f compose.local.yml down #terminate the application
```

### Access the Application

You should access the application through the PORT mapped to the Traefik container.
e.g. `localhost:9000`
28 changes: 28 additions & 0 deletions docker/client.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! docker should be run from the root directory of the project
FROM node:20.10.0-slim as build

# Set the working directory inside the container
WORKDIR /dtaas/client

# Copy package.json and package-lock.json to the working directory
COPY ./client/package.json ./

# Install dependencies
RUN yarn install --immutable --immutable-cache --check-cache

# Copy the rest of the application code to the working directory
COPY ./client/ .

# Build the React app
RUN yarn build


FROM node:20.10.0-slim
# Copy the build output to serve
COPY --from=build /dtaas/client/build /dtaas/client/build
COPY --from=build /dtaas/client/package.json /dtaas/client/package.json

WORKDIR /dtaas/client
RUN npm i -g serve
# Define the command to run your app
CMD ["yarn", "start"]
44 changes: 44 additions & 0 deletions docker/compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3'

services:
client:
build:
context: ../
dockerfile: ./docker/client.dockerfile
ports:
- "4000:4000"
volumes:
- "../client/config/dev.js:/dtaas/client/build/env.js"
libms:
build:
context: ../
dockerfile: ./docker/libms.dockerfile
ports:
- "4001:4001"
volumes:
- "../deploy/config/lib.docker:/dtaas/libms/.env"
- "../files:/dtaas/libms/files"

ml-workspace-user1:
image: mltooling/ml-workspace-minimal:0.13.2
container_name: ml-workspace-user1
ports:
- "8090:8080"
volumes:
- "../files/user1:/workspace"
- "../files/common:/workspace/common"
environment:
- AUTHENTICATE_VIA_JUPYTER
- WORKSPACE_BASE_URL=user1
shm_size: 512m

traefik-gateway:
image: traefik:v2.10
container_name: traefik-gateway
ports:
- "9000:80"
volumes:
- "../servers/config/gateway/traefik.yml:/etc/traefik/traefik.yml"
- "../servers/config/gateway/auth:/etc/traefik/auth"
- "../servers/config/gateway/dynamic/fileConfig.docker.yml:/etc/traefik/dynamic/fileConfig.yml"
- "/var/run/docker.sock:/var/run/docker.sock"
Loading

0 comments on commit 0c79aec

Please sign in to comment.