Skip to content

Commit

Permalink
build: update build structure and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mithenks committed Apr 11, 2024
1 parent 1f2458b commit 0ad004e
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 55 deletions.
16 changes: 0 additions & 16 deletions .bmeme/bin/app

This file was deleted.

13 changes: 0 additions & 13 deletions .bmeme/docker-compose.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .env

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Docker Build CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
docker-build:
name: Run docker build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create marvin:build docker image
run: docker build -f docker/Dockerfile.app -t marvin:build .
- name: Create executable using marvin:build docker image
run: docker build -f docker/Dockerfile.dist -t marvin:dist .
13 changes: 4 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
/app/target/

### STS ###
.apt_generated
Expand All @@ -16,12 +15,8 @@
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/.vscode/

/.cache/

/docker/bob-s-home
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ Packages and technologies used:
* [GraalVM](https://www.graalvm.org/)
* [Native image](https://www.graalvm.org/reference-manual/native-image/)

This project uses [bmeme/mn-dev](https://hub.docker.com/r/bmeme/mn-dev) image from [BMEME](https://www.bmeme.com).

## Package the CLI application

Run the docker container
```bash
$ docker-compose up -d
$ ./go-in.sh
```

Package your application
```bash
$ ./cmvn clean compile test package
[marvin-app@docker]:/usr/src/app$ mvn clean package
```

You will find the runnable application in `app/target/marvin`.
3 changes: 0 additions & 3 deletions cmvn

This file was deleted.

15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
app:
build:
context: .
dockerfile: docker/Dockerfile.app
entrypoint: /bin/sleep infinity
working_dir: /usr/src/app
volumes:
- "./app/:/usr/src/app"
- "./.cache:/usr/src/cache"
- "./docker/bob-s-home:/home/bob"
environment:
- TERM=xterm-256color
- TZ=Europe/Rome
- MAVEN_OPTS=-Duser.home=/usr/src/cache/
47 changes: 47 additions & 0 deletions docker/Dockerfile.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM debian:bookworm-slim as build

RUN apt-get update && \
apt-get install -y git unzip zip curl build-essential zlib1g-dev && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN cd /opt && \
curl -L https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz \
--output graalvm-jdk-21_linux-x64_bin.tar.gz && \
mkdir /opt/graalvm && \
tar xf graalvm-jdk-21_linux-x64_bin.tar.gz -C graalvm --strip-components 1&& \
rm -f graalvm-jdk-21_linux-x64_bin.tar.gz

ARG MAVEN_VERSION=3.9.6

RUN cd /opt && \
curl -L https://downloads.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
--output apache-maven-${MAVEN_VERSION}-bin.tar.gz && \
mkdir /opt/maven && \
tar xf apache-maven-${MAVEN_VERSION}-bin.tar.gz -C maven --strip-components 1 && \
rm -f apache-maven-${MAVEN_VERSION}-bin.tar.gz

ARG MN_VERSION=4.3.7

RUN cd /opt && \
curl -L https://github.com/micronaut-projects/micronaut-starter/releases/download/v${MN_VERSION}/micronaut-cli-${MN_VERSION}.zip \
--output micronaut-cli-${MN_VERSION}.zip && \
unzip micronaut-cli-${MN_VERSION}.zip && \
rm micronaut-cli-${MN_VERSION}.zip && \
mv micronaut-cli-${MN_VERSION} micronaut

ENV PATH="${PATH}:/opt/graalvm/bin:/opt/maven/bin:/opt/micronaut/bin"
ENV JAVA_HOME="/opt/graalvm"

ARG FIX_UID
ARG FIX_GID

ARG DOCKER_USER=bob
ARG DOCKER_GROUP=bob

RUN addgroup --gid 1000 bob && \
adduser --ingroup bob --uid 1000 --disabled-password bob

ADD docker/fix-perm.sh /fix-perm.sh
RUN chmod +x /fix-perm.sh && /fix-perm.sh

USER bob
6 changes: 6 additions & 0 deletions docker/Dockerfile.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM marvin:build as build

COPY --chown=bob app /app
WORKDIR /app

RUN mvn --no-transfer-progress clean package
6 changes: 6 additions & 0 deletions docker/bob-s-home/.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

PS1='\[\033[01;32m\][\[\033[01;32;4m\]marvin-app@docker\[\033[00m\]\[\033[01;32m\]]\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\$ \[\033[00m\]'

alias ls="ls --color"
alias mvn="mvn --no-transfer-progress"

42 changes: 42 additions & 0 deletions docker/fix-perm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

DOCKER_USER_UID=`id -u ${DOCKER_USER}`
DOCKER_GROUP_GID=`id -g ${DOCKER_GROUP}`

echo "user: ${DOCKER_USER} userId: ${DOCKER_USER_UID} fixId: ${FIX_UID}"

if [[ ! -z "$FIX_UID" ]] && [[ "$FIX_UID" != "$DOCKER_USER_UID" ]]; then
echo "Fixing UID permissions"

# Check if $FIX_UID already exists in container
PREV_USER=`getent passwd $FIX_UID | cut -d: -f1`
if [ ! -z "$PREV_USER" ]; then
# Move data from FIX_UID to 888
find / -user ${FIX_UID} -exec chown -h 888 {} \; 2>/dev/null
usermod -u 888 $PREV_USER
fi

find / -user ${DOCKER_USER_UID} -exec chown -h ${FIX_UID} {} \; 2>/dev/null
usermod -u ${FIX_UID} ${DOCKER_USER}
else
echo "UID permissions are ok"
fi

if [[ ! -z "$FIX_GID" ]] && [[ "$FIX_GID" != "$DOCKER_GROUP_GID" ]]; then
echo "Fixing GID permissions"

# Check if $FIX_GID already exists in container
PREV_GROUP=`getent group $FIX_GID | cut -d: -f1`
if [ ! -z "$PREV_GROUP" ]; then
# Move data from FIX_GID to 888
find / -group ${FIX_GID} -exec chgrp -h 888 {} \; 2>/dev/null
groupmod -g 888 $PREV_GROUP
fi

find / -group ${DOCKER_GROUP_GID} -exec chgrp -h ${FIX_GID} {} \; 2>/dev/null
groupmod -g ${FIX_GID} ${DOCKER_GROUP}
else
echo "GID permissions are ok"
fi

exec "$@"
12 changes: 12 additions & 0 deletions go-in.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -ex

# Build docker containers
docker compose build --pull --build-arg FIX_UID="$(id -u)" --build-arg FIX_GID="$(id -g)"

# Start docker environment
docker compose up -d

# Login to docker container
docker compose exec app bash
3 changes: 0 additions & 3 deletions mn

This file was deleted.

0 comments on commit 0ad004e

Please sign in to comment.