mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Review Docker management (#1113)
* Review Docker management ( linked with #934 ) * fix comment by @balloob * Explicit remove of package-lock.json * moved on feature branch, merge docker scripts, added documetation * Used alphine as requested by @balloob on https://github.com/home-assistant/home-assistant-polymer/pull/947 and followed the @mcspr comment https://github.com/home-assistant/home-assistant-polymer/issues/934 * Remove package-lock from gitignore, we don't use npm * Update for new build instructions
This commit is contained in:
parent
94006a843c
commit
d32d334a2e
28
Dockerfile
28
Dockerfile
@ -1,25 +1,31 @@
|
|||||||
FROM node:8.2.1-alpine
|
FROM node:8.9-alpine
|
||||||
|
|
||||||
# install yarn
|
# install yarn
|
||||||
ENV PATH /root/.yarn/bin:$PATH
|
ENV PATH /root/.yarn/bin:$PATH
|
||||||
|
|
||||||
|
## Install/force base tools
|
||||||
RUN apk update \
|
RUN apk update \
|
||||||
&& apk add curl bash binutils tar git python3 \
|
&& apk add make g++ curl bash binutils tar git python2 python3 \
|
||||||
&& rm -rf /var/cache/apk/* \
|
&& rm -rf /var/cache/apk/* \
|
||||||
&& /bin/bash \
|
&& /bin/bash \
|
||||||
&& touch ~/.bashrc \
|
&& touch ~/.bashrc
|
||||||
&& curl -o- -L https://yarnpkg.com/install.sh | bash
|
|
||||||
|
|
||||||
|
## Install yarn
|
||||||
|
RUN curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||||
|
|
||||||
|
## Setup the project
|
||||||
RUN mkdir -p /frontend
|
RUN mkdir -p /frontend
|
||||||
|
|
||||||
WORKDIR /frontend
|
WORKDIR /frontend
|
||||||
|
|
||||||
ENV NODE_ENV production
|
COPY package.json yarn.lock ./
|
||||||
|
|
||||||
COPY package.json ./
|
RUN yarn install --frozen-lockfile
|
||||||
RUN yarn
|
|
||||||
|
|
||||||
COPY bower.json ./
|
|
||||||
RUN ./node_modules/.bin/bower install --allow-root
|
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
CMD [ "/bin/bash", "./script/build_frontend" ]
|
|
||||||
|
COPY script/docker_entrypoint.sh /usr/bin/docker_entrypoint.sh
|
||||||
|
|
||||||
|
RUN chmod +x /usr/bin/docker_entrypoint.sh
|
||||||
|
|
||||||
|
CMD [ "docker_entrypoint.sh" ]
|
||||||
|
12
README.md
12
README.md
@ -16,6 +16,18 @@ This is the repository for the official [Home Assistant](https://home-assistant.
|
|||||||
- Gallery: `cd gallery && script/develop_gallery`
|
- Gallery: `cd gallery && script/develop_gallery`
|
||||||
- Hass.io: [Instructions](https://developers.home-assistant.io/docs/en/hassio_hass.html)
|
- Hass.io: [Instructions](https://developers.home-assistant.io/docs/en/hassio_hass.html)
|
||||||
|
|
||||||
|
## Frontend development
|
||||||
|
|
||||||
|
### Classic environment
|
||||||
|
A complete guide can be found at the following [link](https://www.home-assistant.io/developers/frontend/). It describes a short guide for the build of project.
|
||||||
|
|
||||||
|
### Docker environment
|
||||||
|
It is possible to compile the project and/or run commands in the development environment having only the [Docker](https://www.docker.com) pre-installed in the system. On the root of project you can do:
|
||||||
|
* `sh ./script/docker_run.sh build` Build all the project with one command
|
||||||
|
* `sh ./script/docker_run.sh bash` Open an interactive shell (the same environment generated by the *classic environment*) where you can run commands. This bash work on your project directory and any change on your file is automatically present within your build bash.
|
||||||
|
|
||||||
|
**Note**: if you have installed `npm` in addition to the `docker`, you can use the commands `npm run docker_build` and `npm run bash` to get a full build or bash as explained above
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Home Assistant is open-source and Apache 2 licensed. Feel free to browse the repository, learn and reuse parts in your own projects.
|
Home Assistant is open-source and Apache 2 licensed. Feel free to browse the repository, learn and reuse parts in your own projects.
|
||||||
|
@ -10,7 +10,9 @@
|
|||||||
"build": "script/build_frontend",
|
"build": "script/build_frontend",
|
||||||
"lint": "eslint src hassio/src gallery/src test-mocha && polymer lint",
|
"lint": "eslint src hassio/src gallery/src test-mocha && polymer lint",
|
||||||
"mocha": "node_modules/.bin/mocha --opts test-mocha/mocha.opts",
|
"mocha": "node_modules/.bin/mocha --opts test-mocha/mocha.opts",
|
||||||
"test": "npm run lint && npm run mocha"
|
"test": "npm run lint && npm run mocha",
|
||||||
|
"docker_build": "sh ./script/docker_run.sh build $npm_package_version",
|
||||||
|
"bash": "sh ./script/docker_run.sh bash $npm_package_version"
|
||||||
},
|
},
|
||||||
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
|
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
14
script/docker_entrypoint.sh
Normal file
14
script/docker_entrypoint.sh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Docker entry point inspired by travis build and script/build_frontend
|
||||||
|
|
||||||
|
# Stop on errors
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Build the frontend but not used the npm run build
|
||||||
|
/bin/bash script/build_frontend
|
||||||
|
|
||||||
|
# TEST
|
||||||
|
npm run test
|
||||||
|
|
||||||
|
#
|
||||||
|
#xvfb-run wct
|
103
script/docker_run.sh
Executable file
103
script/docker_run.sh
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Basic Docker Management scripts
|
||||||
|
# With this script you can build software, or enter an agnostic development environment and run commands interactively.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
check_mandatory_tools(){
|
||||||
|
if [ "x$(which docker)" == "x" ]; then
|
||||||
|
echo "UNKNOWN - Missing docker binary! Are you sure it is installed and reachable?"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker info > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "UNKNOWN - Unable to talk to the docker daemon! Maybe the docker daemon is not running"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_dev_image(){
|
||||||
|
if [[ "$(docker images -q ${IMAGE_NAME}:$IMAGE_TAG 2> /dev/null)" == "" ]]; then
|
||||||
|
echo "UNKNOWN - Can't find the development docker image ${IMAGE_NAME}:$IMAGE_TAG"
|
||||||
|
while true; do
|
||||||
|
read -p "Do you want to create it now?" yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) create_image; break;;
|
||||||
|
[Nn]* ) exit 3;;
|
||||||
|
* ) echo "Please answer y or n";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Building the basic image for compiling the production frontend
|
||||||
|
create_image(){
|
||||||
|
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Execute interactive bash on basic image
|
||||||
|
#
|
||||||
|
run_bash_on_docker(){
|
||||||
|
|
||||||
|
check_dev_image
|
||||||
|
|
||||||
|
docker run -it \
|
||||||
|
-v $PWD/:/frontend/ \
|
||||||
|
-v /frontend/node_modules \
|
||||||
|
-v /frontend/bower_components \
|
||||||
|
${IMAGE_NAME}:${IMAGE_TAG} /bin/bash
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Execute the basic image for compiling the production frontend
|
||||||
|
#
|
||||||
|
build_all(){
|
||||||
|
|
||||||
|
check_dev_image
|
||||||
|
|
||||||
|
docker run -it \
|
||||||
|
-v $PWD/:/frontend/ \
|
||||||
|
-v /frontend/node_modules \
|
||||||
|
-v /frontend/bower_components \
|
||||||
|
${IMAGE_NAME}:${IMAGE_TAG} /bin/bash script/build_frontend
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Init Global Variable
|
||||||
|
IMAGE_NAME=home_assistant_fe_image
|
||||||
|
IMAGE_TAG=${2:-latest}
|
||||||
|
|
||||||
|
check_mandatory_tools
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
setup_env)
|
||||||
|
create_image
|
||||||
|
;;
|
||||||
|
bash)
|
||||||
|
run_bash_on_docker
|
||||||
|
;;
|
||||||
|
build)
|
||||||
|
build_all
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "NAME"
|
||||||
|
echo " Docker Management."
|
||||||
|
echo ""
|
||||||
|
echo "SYNOPSIS"
|
||||||
|
echo " ${0} command [version]"
|
||||||
|
echo ""
|
||||||
|
echo "DESCRIPTION"
|
||||||
|
echo " With this script you can build software, or enter an agnostic development environment and run commands interactively."
|
||||||
|
echo ""
|
||||||
|
echo " The command are:"
|
||||||
|
echo " setup_env Create develop images"
|
||||||
|
echo " bash Run bash on develop enviroments"
|
||||||
|
echo " build Run silent build"
|
||||||
|
echo ""
|
||||||
|
echo " The version is optional, if not inserted it assumes \"latest\". "
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
Loading…
x
Reference in New Issue
Block a user