Add frontend build env (#9)
This commit is contained in:
parent
7f5510391f
commit
05783ea334
4 changed files with 197 additions and 0 deletions
24
build-scripts/frontend-build-env/Dockerfile
Normal file
24
build-scripts/frontend-build-env/Dockerfile
Normal file
|
@ -0,0 +1,24 @@
|
|||
FROM ubuntu:16.04
|
||||
|
||||
# setup locals
|
||||
RUN apt-get update && apt-get install -y \
|
||||
locales \
|
||||
curl \
|
||||
apt-transport-https \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& ln -s /usr/bin/nodejs /usr/bin/node
|
||||
RUN locale-gen en_US.UTF-8
|
||||
ENV LANG en_US.UTF-8
|
||||
|
||||
# install yaml
|
||||
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
|
||||
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
|
||||
&& apt-get update && apt-get install -y \
|
||||
nodejs \
|
||||
npm \
|
||||
yarn \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY run-build.sh /
|
||||
|
||||
WORKDIR /hassio
|
93
build-scripts/frontend-build-env/create_frontend.sh
Normal file
93
build-scripts/frontend-build-env/create_frontend.sh
Normal file
|
@ -0,0 +1,93 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
BUILD_CONTAINER_NAME=hassio-frontend-$$
|
||||
BRANCH=dev
|
||||
REPOSITORY=https://github.com/home-assistant/hassio
|
||||
|
||||
cleanup() {
|
||||
echo "[INFO] Cleanup."
|
||||
|
||||
# Stop docker container
|
||||
echo "[INFO] Cleaning up hassio-frontend container."
|
||||
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
|
||||
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
|
||||
|
||||
if [ "$1" == "fail" ]; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
trap 'cleanup fail' SIGINT SIGTERM
|
||||
|
||||
# Get the absolute script location
|
||||
pushd "$(dirname "$0")" > /dev/null 2>&1
|
||||
SCRIPTPATH=$(pwd)
|
||||
popd > /dev/null 2>&1
|
||||
|
||||
help () {
|
||||
cat << EOF
|
||||
Script for hassio frontend build
|
||||
create_frontend [options]
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Display this help and exit.
|
||||
|
||||
-r, --repository
|
||||
Repository to fetch hassio
|
||||
|
||||
-b, --branch
|
||||
Branch to checkout
|
||||
EOF
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key=$1
|
||||
case $key in
|
||||
-h|--help)
|
||||
help
|
||||
exit 0
|
||||
;;
|
||||
-r|--repository)
|
||||
REPOSITORY=$2
|
||||
shift
|
||||
;;
|
||||
-b|--branch)
|
||||
BRANCH=$1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "[WARNING] $0 : Argument '$1' unknown. Ignoring."
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Get the absolute script location
|
||||
pushd "$(dirname "$0")" > /dev/null 2>&1
|
||||
SCRIPTPATH=$(pwd)
|
||||
popd > /dev/null 2>&1
|
||||
|
||||
BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH}
|
||||
WORKSPACE=${BUILD_DIR:=$SCRIPTPATH}/hassio-frontend
|
||||
|
||||
echo "[INFO] Checkout hass.io repository"
|
||||
git clone "$REPOSITORY" "$WORKSPACE"
|
||||
cd "$WORKSPACE" && git checkout "$BRANCH"
|
||||
git submodule update --init --recursive
|
||||
|
||||
echo "[INFO] Start frontend build"
|
||||
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
|
||||
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
|
||||
docker run --rm \
|
||||
-v "$WORKSPACE":/hassio \
|
||||
--name $BUILD_CONTAINER_NAME \
|
||||
homeassistant/frontend-build-env \
|
||||
/run-build.sh
|
||||
|
||||
echo "[INFO] cleanup WORKSPACE"
|
||||
rm -rf "$WORKSPACE"
|
||||
|
||||
cleanup "okay"
|
||||
exit 0
|
65
build-scripts/frontend-build-env/create_frontend_env.sh
Normal file
65
build-scripts/frontend-build-env/create_frontend_env.sh
Normal file
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DOCKER_IMAGE=${DOCKER_IMAGE:="homeassistant/frontend-build-env"}
|
||||
DOCKER_PUSH="false"
|
||||
|
||||
# Get the absolute script location
|
||||
pushd "$(dirname "$0")" > /dev/null 2>&1
|
||||
SCRIPTPATH=$(pwd)
|
||||
popd > /dev/null 2>&1
|
||||
|
||||
help () {
|
||||
cat << EOF
|
||||
Script for hassio frontend build environment
|
||||
create_frontend_env [options]
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Display this help and exit.
|
||||
|
||||
-t, --tag TAG
|
||||
Version/Tag of $DOCKER_IMAGE.
|
||||
-p, --push
|
||||
Upload the build to docker hub.
|
||||
EOF
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key=$1
|
||||
case $key in
|
||||
-h|--help)
|
||||
help
|
||||
exit 0
|
||||
;;
|
||||
-t|--tag)
|
||||
DOCKER_TAG=$2
|
||||
shift
|
||||
;;
|
||||
-p|--push)
|
||||
DOCKER_PUSH="true"
|
||||
;;
|
||||
*)
|
||||
echo "[WARNING] $0 : Argument '$1' unknown. Ignoring."
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "$DOCKER_TAG" ]; then
|
||||
echo "[ERROR] please set a tag!"
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build
|
||||
docker build --pull --tag "$DOCKER_IMAGE:$DOCKER_TAG" -f "$SCRIPTPATH/Dockerfile" "$SCRIPTPATH"
|
||||
|
||||
# Tag
|
||||
docker tag "$DOCKER_IMAGE:$DOCKER_TAG" "$DOCKER_IMAGE:latest"
|
||||
|
||||
if [ "$DOCKER_PUSH" == "true" ]; then
|
||||
docker push "$DOCKER_IMAGE:$DOCKER_TAG"
|
||||
docker push "$DOCKER_IMAGE:latest"
|
||||
fi
|
15
build-scripts/frontend-build-env/run-build.sh
Normal file
15
build-scripts/frontend-build-env/run-build.sh
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# build frontend
|
||||
yarn
|
||||
./node_modules/.bin/bower install --allow-root
|
||||
yarn run frontend_prod
|
||||
|
||||
# prepare data
|
||||
cd build-temp/
|
||||
gzip -f -k -9 ./*.html
|
||||
|
||||
# move to frontend
|
||||
cp -f hassio-main.html ../hassio/panel/
|
||||
cp -f hassio-main.html.gz ../hassio/panel/
|
Loading…
Add table
Add a link
Reference in a new issue