-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
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,36 @@ | ||
FROM codercom/code-server:latest AS code-server | ||
FROM crops/yocto:ubuntu-@UBUNTU_VERSION@-base | ||
|
||
USER root | ||
|
||
ADD resources/shell-wrapper /usr/bin/shell-wrapper | ||
ADD resources/install_clean /usr/bin/install_clean | ||
ADD resources/yocto-env /opt/tools/yocto-env | ||
|
||
RUN install_clean vim git wget libncurses5-dev python3-distutils | ||
|
||
# install vs-code | ||
COPY --from=code-server /usr/lib/code-server /opt/code-server | ||
RUN rm /opt/code-server/code-server | ||
ADD resources/code-server.yaml /opt/ | ||
|
||
# Set the locale | ||
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ | ||
locale-gen | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
|
||
# Add tools to PATH | ||
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/code-server:/opt/code-server/bin:/opt/tools | ||
|
||
ADD @ENV_FOLDER@ /opt/tools | ||
RUN install_clean jq @EXTRA_PKGS@ | ||
|
||
# Expose port 8080 (vs-code) and 8000 (free to play) | ||
EXPOSE 8080 | ||
EXPOSE 8000 | ||
USER yoctouser | ||
CMD shell-wrapper | ||
|
||
#:vim syntax=dockerfile |
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 @@ | ||
VERSION = $(shell git describe --always) | ||
|
||
deploy: | ||
cat dev-env > dev-env_$(VERSION).sh | ||
echo "" >> dev-env_$(VERSION).sh | ||
echo "PAYLOAD:" >> dev-env_$(VERSION).sh | ||
tar -czf - resources Dockerfile.template >> dev-env_$(VERSION).sh | ||
chmod 555 dev-env_$(VERSION).sh | ||
|
||
default: deploy | ||
|
||
.PHONY: deploy default |
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,55 @@ | ||
#! /bin/bash | ||
|
||
set -e | ||
|
||
VOLUME_NAME=${1:?"Use $0 <chik> to start the development environment"} | ||
FREE_PORT=${2:-8000} | ||
CODE_PORT=${3:-8080} | ||
|
||
function extract_payload { | ||
match=$(grep --text --line-number '^PAYLOAD:$' $0 | cut -d ':' -f 1) | ||
payload_start=$((match + 1)) | ||
tail -n +$payload_start $0 | tar -C $1 -xzf - | ||
} | ||
|
||
# $1 workdir | ||
function create_dockerfile { | ||
ubuntu_version=`jq -cr '.host_ubuntu_version' ${VOLUME_NAME}/manifest.json` | ||
extra_pkgs=`jq -cr '.extra_pkgs // ""' ${VOLUME_NAME}/manifest.json` | ||
mv $1/Dockerfile.template Dockerfile | ||
sed -i "" -e "s/@UBUNTU_VERSION@/${ubuntu_version}/" Dockerfile | ||
sed -i "" -e "s/@EXTRA_PKGS@/${extra_pkgs}/" Dockerfile | ||
sed -i "" -e "s/@ENV_FOLDER@/${VOLUME_NAME}/" Dockerfile | ||
} | ||
|
||
function create_volume { | ||
if [[ $(docker volume ls --filter "name=${VOLUME_NAME}" -q | wc -l ) -eq 0 ]]; then | ||
echo "creating volume and copying setup script into it" | ||
docker volume create --name ${VOLUME_NAME} | ||
docker run -it --rm -v ${VOLUME_NAME}:/workdir busybox \ | ||
/bin/sh -c "mkdir -p /workdir/src && chown -R 1000:1000 /workdir" | ||
fi | ||
} | ||
|
||
function start_container { | ||
echo "Building the development container" | ||
docker build -t ${VOLUME_NAME} -f Dockerfile . | ||
|
||
echo "Cleaning up old containers" | ||
docker rmi $(docker images -qa -f 'dangling=true') || echo "Nothing to remove" | ||
|
||
echo "Starting the development container" | ||
docker run --rm -it --privileged -v ${VOLUME_NAME}:/home/yoctouser -p ${FREE_PORT}:8000 -p ${CODE_PORT}:8080 ${VOLUME_NAME} | ||
} | ||
|
||
function main { | ||
workdir=`mktemp -d` | ||
extract_payload $workdir | ||
create_dockerfile $workdir | ||
rm -rf $workdir | ||
create_volume | ||
start_container | ||
} | ||
|
||
main ${@} | ||
exit 0 |
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,3 @@ | ||
bind-addr: 0.0.0.0:8080 | ||
auth: none | ||
cert: false |
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,16 @@ | ||
#!/bin/bash -e | ||
# Apt installer helper for Docker images | ||
|
||
ARGS="$*" | ||
NO_RECOMMENDS="--no-install-recommends" | ||
RECOMMENDS="--install-recommends" | ||
if [[ $ARGS =~ "$RECOMMENDS" ]]; then | ||
NO_RECOMMENDS="" | ||
ARGS=$(sed "s/$RECOMMENDS//g" <<<"$ARGS") | ||
fi | ||
|
||
echo "Installing $ARGS" | ||
|
||
apt-get -q update && apt-get -qy install $NO_RECOMMENDS $ARGS \ | ||
&& apt-get -qy autoremove \ | ||
&& apt-get clean |
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,9 @@ | ||
#! /bin/bash | ||
|
||
code-server --config /opt/code-server.yaml 2>&1 1>/dev/null & | ||
|
||
pushd src | ||
python3 -m http.server 1>/dev/null 2>&1 & | ||
popd | ||
|
||
exec bash -i |
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,59 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -u | ||
|
||
TOOLS_PATH="/opt/tools" | ||
JCONF=${CONFIG:-"${TOOLS_PATH}/manifest.json"} | ||
MACHINE=${MACHINE:-`jq -r '.machine' ${JCONF}`} | ||
|
||
directory=${HOME}/src | ||
|
||
function main { | ||
mkdir -p ${directory} | ||
cd ${directory} | ||
fetch_yocto | ||
start_subshell | ||
} | ||
|
||
function checkout { | ||
revision=${4:-"HEAD"} | ||
|
||
echo "Cloning $1" | ||
git clone $2 -b $3 $1 | ||
pushd $1 | ||
git checkout ${revision} | ||
popd | ||
} | ||
|
||
function extract { | ||
echo "Extracting $2" | ||
tar -xf $2 $1 | ||
} | ||
|
||
function fetch_yocto { | ||
mkdir -p yocto/src | ||
pushd yocto/src | ||
jq -c '.layers[]' ${JCONF} | while read i; do | ||
path=$(jq -r '.path' <<< $i) | ||
if [[ ! -d ${path} ]]; then | ||
method=$(jq -r '.method' <<< $i) | ||
args=$(jq -r '.args | @sh' <<< $i) | ||
eval "$method $path $args" | ||
fi | ||
done | ||
popd | ||
} | ||
|
||
function start_subshell { | ||
cd yocto | ||
set +u | ||
export MACHINE=${MACHINE} | ||
export PROMPT_COMMAND="PS1='(yocto) \[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" | ||
export TEMPLATECONF="/opt/tools/defconfig" | ||
|
||
source src/poky/oe-init-build-env "build-${MACHINE}" | ||
exec bash -i | ||
} | ||
|
||
main ${@} |