-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: update build structure and workflow
- Loading branch information
Showing
14 changed files
with
151 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |