Skip to content

Commit

Permalink
wip: build_app script
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed Feb 19, 2024
1 parent 430cb89 commit 3b766d7
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 63 deletions.
9 changes: 0 additions & 9 deletions .dockerignore

This file was deleted.

43 changes: 43 additions & 0 deletions app.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Use a builder
FROM node:16-bookworm-slim as Builder
LABEL maintainer="[email protected]"

# git is required to pull some node packages from github
RUN DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get --no-install-recommends --yes install \
ca-certificates git

COPY . /opt/kalisio

# Setup kli
WORKDIR /opt/kalisio/kli
RUN yarn install

# Setup app
WORKDIR /opt/kalisio/
RUN node /opt/kalisio/kli /opt/kalisio/kli.js --install

# Copy to final container
FROM node:16-bookworm-slim
LABEL maintainer="[email protected]"

ARG APP
ARG FLAVOR
ARG BUILD_NUMBER

ENV BUILD_NUMBER=$BUILD_NUMBER
ENV NODE_APP_INSTANCE=$FLAVOR

COPY --from=Builder --chown=node:node /opt/kalisio /opt/kalisio
# From now on, run stuff as 'node'
USER node

# Link the modules
WORKDIR /opt/kalisio
RUN node /opt/kalisio/kli /opt/kalisio/kli.js --link

# Run the app
WORKDIR /opt/kalisio/${APP}
EXPOSE 8081
CMD [ "yarn", "prod" ]
20 changes: 20 additions & 0 deletions app.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ignore verything
*

# Except these
!kli.js
!kli/*
!feathers-s3/*
!feathers-import-export/*
!feathers-webpush/*
!kdk/*
!kapp/*

# But ignore these anyway
**/node_modules
**/npm-debug.log
**/*Dockerfile
**/docker-compose*
**/*dockerignore
**/.git
**/.gitignore
41 changes: 0 additions & 41 deletions dockerfile

This file was deleted.

69 changes: 57 additions & 12 deletions scripts/build_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ ROOT_PATH=$(dirname "$THIS_PATH")

. "$THIS_PATH/kash/kash.sh"

## Parse options
##

PUBLISH=false
while getopts "p" option; do
case $option in
p) # defines mongo version
PUBLISH=true;;
*)
;;
esac
done

### Handle CI/dev environment
###

if [ "$CI" = true ]; then
begin_group "Fetching project dependencies ..."

Expand All @@ -19,30 +35,59 @@ if [ "$CI" = true ]; then

# clone developement
git clone --depth 1 "https://$GITHUB_DEVELOPMENT_PAT@github.com/kalisio/development.git" "$DEVELOPMENT_REPO_DIR"

get_app_infos "$ROOT_PATH" "$DEVELOPMENT_REPO_DIR/workspaces/apps"
APP="${APP_INFOS[0]}"
VERSION="${APP_INFOS[1]}"
FLAVOR="${APP_INFOS[2]}"
KLI_FILE="${APP_INFOS[3]}"

run_kli "$WORKSPACE_DIR" "$KLI_FILE" 16
# clone kli
git clone --depth 1 "https://github.com/kalisio/kli.git" "$WORKSPACE_DIR/kli"
cd "$WORKSPACE_DIR/kli" && yarn install && cd ~-
# clone app dependencies
init_app_infos "$ROOT_PATH" "$DEVELOPMENT_REPO_DIR/workspaces/apps"
KLI_FILE=$(get_app_kli_file)
node "$WORKSPACE_DIR/kli" "$KLI_FILE" --clone --shallow-clone

end_group "Fetching project dependencies ..."

echo "Used kli file $KLI_FILE ..."
echo "About to build app ${APP}@${VERSION} ($FLAVOR) ..."
else
WORKSPACE_DIR="$KALISIO_DEVELOPMENT_DIR"
DEVELOPMENT_REPO_DIR="$KALISIO_DEVELOPMENT_DIR/development"

init_app_infos "$ROOT_PATH" "$DEVELOPMENT_REPO_DIR/workspaces/apps"
fi

APP=$(get_app_name)
VERSION=$(get_app_version)
FLAVOR=$(get_app_flavor)

echo "About to build ${APP} v${VERSION}-$FLAVOR ..."

## Load project env
##

. "$DEVELOPMENT_REPO_DIR/workspaces/apps/apps.sh" kapp

## Build app
## Build container
##

use_node 16
yarn pwa:build
# kli file is used in container to install, link
KLI_FILE=$(get_app_kli_file)
cp "$KLI_FILE" "$WORKSPACE_DIR/kli.js"

IMAGE_NAME="kalisio/$APP"
IMAGE_TAG="$VERSION-$FLAVOR"

docker login --username "$KALISIO_DOCKERHUB_USERNAME" --password-stdin < "$KALISIO_DOCKERHUB_PASSWORD"
# DOCKER_BUILDKIT is here to be able to use Dockerfile specific dockerginore (app.Dockerfile.dockerignore)
DOCKER_BUILDKIT=1 docker build \
--build-arg APP="$APP" \
--build-arg FLAVOR="$FLAVOR" \
--build-arg BUILD_NUMBER=1 \
-f app.Dockerfile \
-t "$IMAGE_NAME:$IMAGE_TAG" \
"$WORKSPACE_DIR"
docker tag "$IMAGE_NAME:$IMAGE_TAG" "$IMAGE_NAME:$FLAVOR"

if [ "$PUBLISH" = true ]; then
docker push "$IMAGE_NAME:$IMAGE_TAG"
docker push "$IMAGE_NAME:$FLAVOR"
fi

docker logout
2 changes: 1 addition & 1 deletion scripts/kash
Submodule kash updated 1 files
+101 −9 kash.sh

0 comments on commit 3b766d7

Please sign in to comment.