diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7195a9e5..66f6bf0f4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,22 @@ variables: GIT_SUBMODULE_STRATEGY: recursive +stages: + - build_docker + - build_and_deploy_docker + - build_and_deploy_website + - test + + +.docker: &docker + image: docker:1.11 + services: + - docker:dind + +.docker_build: &docker_build + script: + - docker build -t $LIGO_REGISTRY_IMAGE:latest -f ./docker/Dockerfile . + .before_script: &before_script before_script: # Install dependencies @@ -29,6 +45,7 @@ variables: local-dune-job: <<: *before_script + stage: test script: - vendors/opam-repository-tools/rewrite-local-opam-repository.sh - opam repository add localrepo "file://$PWD/vendors/ligo-opam-repository-local-generated/" @@ -43,6 +60,7 @@ local-dune-job: local-repo-job: <<: *before_script + stage: test script: - vendors/opam-repository-tools/rewrite-local-opam-repository.sh - opam repository add localrepo "file://$PWD/vendors/ligo-opam-repository-local-generated/" @@ -51,6 +69,7 @@ local-repo-job: remote-repo-job: <<: *before_script + stage: test script: # Add repository - opam repository add ligo-repository https://gitlab.com/ligolang/ligo.git @@ -62,14 +81,29 @@ remote-repo-job: #- opam install -y ocp-indent #- opam user-setup install -build-docker-image: - image: docker:1.11 - services: - - docker:dind - script: - - docker build -t marigold/ligo ./docker +# Run a docker build without publishing to the registry +build-current-docker-image: + stage: build_docker + <<: *docker + <<: *docker_build + except: + - master + +# When a MR/PR is merged to master +# take the previous build and publish it to Docker Hub +build-and-publish-latest-docker-image: + stage: build_and_deploy_docker + <<: *docker + <<: *docker_build + after_script: + - docker login -u $LIGO_REGISTRY_USER -p $LIGO_REGISTRY_PASSWORD + - docker push $LIGO_REGISTRY_IMAGE:latest + only: + - master + pages: + stage: build_and_deploy_website image: node:8 before_script: - cd gitlab-pages/website diff --git a/docker/Dockerfile b/docker/Dockerfile index 17bcd147c..5cedfcd58 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,31 +1,31 @@ # We could use one of the nomadiclab's docker images as a base instead -# We're using 4.06 instead of 4.06.1, if this causes problems built a custom 4.06.1 image instead +# We're using 4.06 instead of 4.06.1, if this causes problems build a custom 4.06.1 image instead FROM ocaml/opam2:4.06 USER root +# Add contents of the current directory to /ligo where it can be +# accessed when building the image. +# +# This is useful when building either locally, or on the CI +# because the currently checkout out version (from git) will be used +# to build the image +ADD . /ligo + +# Set the current working directory to /ligo for +# the upcoming scripts +WORKDIR /ligo + # Setup a custom opam repository where ligo is published -RUN git clone https://gitlab.com/ligolang/ligo.git -RUN (cd ligo; vendors/opam-repository-tools/rewrite-local-opam-repository.sh) -RUN opam repo add ligo-opam-repository ./ligo/vendors/ligo-opam-repository-local-generated/ -RUN opam update ligo-opam-repository +RUN sh scripts/setup_ligo_opam_repository.sh # Install required native dependencies -RUN apt-get -y install \ - libev-dev \ - perl \ - pkg-config \ - libgmp-dev \ - libhidapi-dev \ - m4 +RUN sh scripts/install_native_dependencies.sh -# Install ligo RUN opam update -RUN cd ligo/src && \ - opam install . --yes - -RUN eval $(opam env) +# Install ligo +RUN sh scripts/install_ligo_with_dependencies.sh # Use the ligo binary as a default command ENTRYPOINT [ "/home/opam/.opam/4.06/bin/ligo" ] diff --git a/docker/ligo.sh b/docker/ligo.sh deleted file mode 100644 index 246a2f08d..000000000 --- a/docker/ligo.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -docker run -it -v $PWD:$PWD -w $PWD marigold/ligo $@ \ No newline at end of file diff --git a/scripts/build_docker_image.sh b/scripts/build_docker_image.sh new file mode 100755 index 000000000..eb2bdb611 --- /dev/null +++ b/scripts/build_docker_image.sh @@ -0,0 +1 @@ +docker build -t ligolang/ligo -f docker/Dockerfile . \ No newline at end of file diff --git a/scripts/install_ligo_with_dependencies.sh b/scripts/install_ligo_with_dependencies.sh new file mode 100755 index 000000000..9ad969f3f --- /dev/null +++ b/scripts/install_ligo_with_dependencies.sh @@ -0,0 +1 @@ +cd src && opam install . --yes \ No newline at end of file diff --git a/scripts/install_native_dependencies.sh b/scripts/install_native_dependencies.sh new file mode 100755 index 000000000..04d4ce17f --- /dev/null +++ b/scripts/install_native_dependencies.sh @@ -0,0 +1,7 @@ +apt-get -y install \ + libev-dev \ + perl \ + pkg-config \ + libgmp-dev \ + libhidapi-dev \ + m4 \ No newline at end of file diff --git a/docker/installer.sh b/scripts/installer.sh old mode 100644 new mode 100755 similarity index 53% rename from docker/installer.sh rename to scripts/installer.sh index 698207b94..eb56165ca --- a/docker/installer.sh +++ b/scripts/installer.sh @@ -1,16 +1,20 @@ #!/bin/bash # You can run this installer like this: -# curl https://gitlab.com/gabriel.alfour/ligo/blob/master/docker/installer.sh | bash -# Make sure the marigold/ligo image is published at docker hub first +# curl https://gitlab.com/ligolang/ligo/blob/master/scripts/installer.sh | bash +# Make sure the marigold/ligo image is published at docker hub first +set -euET -o pipefail echo "Installing LIGO" # Install the ligo.sh from master -wget https://gitlab.com/gabriel.alfour/ligo/blob/master/docker/ligo.sh +wget https://gitlab.com/ligolang/ligo/blob/master/scripts/ligo.sh # Copy the exucutable to the appropriate directory sudo cp ligo.sh /usr/local/bin/ligo sudo chmod +x /usr/local/bin/ligo rm ligo.sh +# Pull the docker image used by ligo.sh +docker pull ligolang/ligo:latest + # Installation finished, try running 'ligo' from your CLI -echo "Installation successfull, try running 'ligo' now. \n" \ No newline at end of file +echo "Installation successful, try to run 'ligo --help' now. \n" \ No newline at end of file diff --git a/scripts/ligo.sh b/scripts/ligo.sh new file mode 100755 index 000000000..8ccadad8e --- /dev/null +++ b/scripts/ligo.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker run -it -v "$PWD":"$PWD" -w "$PWD" ligolang/ligo:latest "$@" \ No newline at end of file diff --git a/scripts/setup_ligo_opam_repository.sh b/scripts/setup_ligo_opam_repository.sh new file mode 100755 index 000000000..e07eac487 --- /dev/null +++ b/scripts/setup_ligo_opam_repository.sh @@ -0,0 +1,3 @@ +vendors/opam-repository-tools/rewrite-local-opam-repository.sh +opam repo add ligo-opam-repository ./vendors/ligo-opam-repository-local-generated +opam update ligo-opam-repository \ No newline at end of file