From f92e12511b3dc6a46be064d5d09700e4fabc8974 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Tue, 4 Feb 2020 20:31:02 -0500 Subject: [PATCH] Added automatic docker image creation --- .travis.yml | 9 ++++++ packaging/docker-for-binary/Dockerfile.Auto | 34 +++++++++++++++++++++ packaging/docker-for-binary/README.md | 33 +++++++++++++++++++- packaging/docker-for-binary/auto_deploy.sh | 26 ++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 packaging/docker-for-binary/Dockerfile.Auto create mode 100755 packaging/docker-for-binary/auto_deploy.sh diff --git a/.travis.yml b/.travis.yml index e46781e58..4cba985e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,11 +24,13 @@ jobs: - mkdir -p ${HOME}/ccache - docker pull $DOCKER_BUILD_IMAGE script: + - echo "build..." - docker run -v "$(pwd):/lbrycrd" -v "${HOME}/ccache:/ccache" -w /lbrycrd -e CCACHE_DIR=/ccache ${DOCKER_IMAGE} packaging/build_${NAME}_64bit.sh before_deploy: - mkdir -p dist - sudo zip -Xj dist/lbrycrd-${NAME}.zip src/lbrycrdd${EXT} src/lbrycrd-cli${EXT} src/lbrycrd-tx${EXT} - sudo zip -Xj dist/lbrycrd-${NAME}-test.zip src/test/test_lbrycrd${EXT} src/test/test_lbrycrd_fuzzy${EXT} + - sudo cp dist/lbrycrd-${NAME}.zip packaging/docker-for-binary/lbrycrd-${NAME}.zip - sha256sum dist/lbrycrd-${NAME}.zip - sha256sum dist/lbrycrd-${NAME}-test.zip deploy: @@ -44,6 +46,13 @@ jobs: on: repo: lbryio/lbrycrd all_branches: true + - provider: script + script: bash packaging/docker-for-binary/auto_deploy.sh ${TRAVIS_BRANCH} + skip_cleanup: true + on: + repo: lbryio/lbrycrd + all_branches: true + condition: $NAME = linux - <<: *build-template name: windows diff --git a/packaging/docker-for-binary/Dockerfile.Auto b/packaging/docker-for-binary/Dockerfile.Auto new file mode 100644 index 000000000..36a968731 --- /dev/null +++ b/packaging/docker-for-binary/Dockerfile.Auto @@ -0,0 +1,34 @@ +FROM ubuntu:18.04 as prep +LABEL MAINTAINER="leopere [at] nixc [dot] us" +## TODO: Implement version pinning. `apt-get install curl=` +RUN apt-get update && \ + apt-get -y install unzip curl build-essential && \ + apt-get autoclean -y && \ + rm -rf /var/lib/apt/lists/* +WORKDIR / +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +COPY ./stuff/start.sh start +COPY ./stuff/healthcheck.sh healthcheck +COPY ./stuff/advance_blocks.sh advance +COPY ./stuff/fix-permissions.c fix-permissions.c +COPY ./lbrycrd-linux.zip lbrycrd-linux.zip + +RUN unzip ./lbrycrd-linux.zip && \ + gcc fix-permissions.c -o fix-permissions && \ + chmod +x ./lbrycrdd ./lbrycrd-cli ./lbrycrd-tx ./start ./healthcheck ./fix-permissions ./advance + +FROM ubuntu:18.04 as app +COPY --from=prep /lbrycrdd /lbrycrd-cli /lbrycrd-tx /start /healthcheck /fix-permissions /advance /usr/bin/ +RUN addgroup --gid 1000 lbrycrd && \ + adduser lbrycrd --uid 1000 --gid 1000 --gecos GECOS --shell /bin/bash --disabled-password --home /data && \ + mkdir /etc/lbry && \ + chown lbrycrd /etc/lbry && \ + chmod a+s /usr/bin/fix-permissions +RUN apt-get update && apt-get -y install wget && apt-get autoclean -y && rm -rf /var/lib/apt/lists/* +VOLUME ["/data"] +WORKDIR /data +HEALTHCHECK CMD /usr/bin/healthcheck +EXPOSE 9246 9245 11337 29245 + +USER lbrycrd +CMD ["start"] diff --git a/packaging/docker-for-binary/README.md b/packaging/docker-for-binary/README.md index bf5f26ccc..4f2d37282 100644 --- a/packaging/docker-for-binary/README.md +++ b/packaging/docker-for-binary/README.md @@ -1,5 +1,36 @@ # lbrycrd Docker image -` + +## Scripts + +There are two scripts `deploy.sh` and `auto_deploy.sh` These are used to create +docker images to push to lbry's Docker Hub. + +### `auto_deploy.sh` + +This script is used by the LBRYcrd's CI. When a branch or tag is built +it will create a docker image for it and push it to DockerHub. This should +not be used outside of the CI environment. In addition to this, the +`Dockerfile.Auto` is associated with this script. This will only run on the +Linux build job. + +#### Requirements + +- You would need to build lbrycrd with the Docker image for reproducible +builds. https://hub.docker.com/repository/docker/lbry/build_lbrycrd +- You will need DockerHub credentials to run this locally. +- When the script is executed you will need the parameter as + `./auto_deploy.sh ${tag_name}` + +### `deploy.sh` + +This can be used locally to manually create a docker image based on a +release. `release_url` is requested as a parameter to the script when +run locally. This will grab the binary from github releases inside the +image build. + +#### Requirements + +- You will need DockerHub credentials to run this locally. ## Configuration diff --git a/packaging/docker-for-binary/auto_deploy.sh b/packaging/docker-for-binary/auto_deploy.sh new file mode 100755 index 000000000..3bc0c45ff --- /dev/null +++ b/packaging/docker-for-binary/auto_deploy.sh @@ -0,0 +1,26 @@ +#!/bin/bash + + +set -euo pipefail +hash docker 2>/dev/null || { echo >&2 'Make sure Docker is installed'; exit 1; } + +set +eo pipefail +docker version | grep -q Server +ret=$? +set -eo pipefail + +if [ $ret -ne 0 ]; then + echo "Cannot connect to Docker server. Is it running? Do you have the right user permissions?" + exit 1 +fi + +if [ -z "$1" ]; then + echo "Docker tag parameter cannot be empty" + exit 1 +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd packaging/docker-for-binary +docker build --tag "lbry/lbrycrd:$1" -f Dockerfile.Auto "$DIR" +echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin +docker push "lbry/lbrycrd:$1"