Skip to content

Instantly share code, notes, and snippets.

@rwb27
Last active January 21, 2019 09:59
Show Gist options
  • Save rwb27/5ab632a2d5ddf0949b052d2fd8754690 to your computer and use it in GitHub Desktop.
Save rwb27/5ab632a2d5ddf0949b052d2fd8754690 to your computer and use it in GitHub Desktop.
Build script for the OpenFlexure Microscope
#!/bin/bash
# Rebuild the openflexure microscope
cd ~rwb34/dev/openflexure_microscope_builds/sparse_checkout/
git fetch
git checkout $1
commit=`git rev-parse --verify HEAD`
builds_dir=../commits
mkdir -p "$builds_dir"
echo "Building commit $commit"
git show -s --oneline
if [[ ! -d "$builds_dir/$commit" ]]; then
rm -rf builds
mkdir builds
python generate_makefile.py --version_numstring ${commit:0:7}
make all
tar -cf builds/all_stl_files.tar builds/*.stl
gzip builds/all_stl_files.tar
mv builds "$builds_dir/$commit"
rm -f ../latest.tar.gz
rm -f ../latest
ln -s "commits/$commit/all_stl_files.tar.gz" ../latest.tar.gz
ln -s "commits/$commit/" ../latest
else
echo "Commit $commit has already been built - delete the directory to rebuild."
fi

Setting up the microscope build server (so far)

sudo apt-get install openscad

mkdir -p ~/dev/openflexure_microscope_builds/sparse_checkout/
cd ~/dev/openflexure_microscope_builds/sparse_checkout/

git init
git config core.sparsecheckout true
echo openscad/ >> .git/info/sparse-checkout
echo generate_makefile.py >> .git/info/sparse-checkout
git remote add -f origin https://github.com/rwb27/openflexure_microscope.git
git pull origin reversed_cantilevered_objective_mount

This did seem to get the latest version, and only the openscad folder. However, it still downloaded about 400Mb of archives!! Is there really that much history there?

python generate_makefile.py
mkdir builds
make all

To rebuild I guess it's even simpler:

#!/bin/bash
# Rebuild the openflexure microscope
cd ~rwb34/dev/openflexure_microscope_builds/sparse_checkout/
git pull

commit=`git rev-parse --verify HEAD`
builds_dir=../commits

if [ -d "$builds_dir/$commit" ]; then
    git checkout $commit
    rm -rf builds
    mkdir builds
    make all
    mv builds "$builds/$commit"
fi

I've updated the build script somewhat in ./rebuild.sh and now simply running ./rebuild.sh origin/master should do the right thing. It will archive old builds by their SHA1, and keep a symlink to the latest one. Next step is some sort of tiny webserver to serve up said folders based on some Git metadata.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment