Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

  1. Default to UTF-8 file.encoding
    ENV LANG C.UTF-8

  2. add a simple script that can auto-detect the appropriate JAVA_HOME value
  3. Wiki Markup
    based on whether the JDK or only the JRE is installed \\
    RUN \{ \ \\
     echo '#!/bin/sh'; \ \\
     echo 'set -e'; \ \\
     echo; \ \\
     echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \ \\
     \} > /usr/local/bin/docker-java-home \ \\
     && chmod +x /usr/local/bin/docker-java-home \\
    ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk \\
    ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin \\
     \\
    ENV JAVA_VERSION 8u212 \\
    ENV JAVA_ALPINE_VERSION 8.212.04-r0 \\
     \\
    RUN set -x \ \\
     && apk add --no-cache \ \\
     openjdk8="$JAVA_ALPINE_VERSION" \ \\
     && \[ "$JAVA_HOME" = "$(docker-java-home)" \] \\
     \\
    #ASPIRE  \\

  4. Set environment variables
    ARG JAVA_MAX_MEMORY=16g
    ENV JAVA_MAX_MEMORY=$JAVA_MAX_MEMORY

    ARG JAVA_INITIAL_MEMORY=1g
    ENV JAVA_INITIAL_MEMORY=$JAVA_INITIAL_MEMORY

    ARG ASPIRE_HOME=/aspire/aspire-distribution-3.2
    ENV ASPIRE_HOME=$ASPIRE_HOME

    ARG ASPIRE_ADMIN_PORT=50505
    ENV ASPIRE_ADMIN_PORT=$ASPIRE_ADMIN_PORT

    ARG ASPIRE_MAVEN_REPOSITORY=/aspire/maven-repository
    ENV ASPIRE_MAVEN_REPOSITORY=$ASPIRE_MAVEN_REPOSITORY

    ARG ASPIRE_MONGODB_URI=xxxxx:27017
    ENV ASPIRE_MONGODB_URI=$ASPIRE_MONGODB_URI

    ARG ASPIRE_ZOOKEEPER_xxxx:2181
    ENV ASPIRE_ZOOKEEPER_URI=$ASPIRE_ZOOKEEPER_URI

    ARG ASPIRE_MAVEN_USERNAME=xxxxx
    ENV ASPIRE_MAVEN_USERNAME=$ASPIRE_MAVEN_USERNAME

    ARG ASPIRE_MAVEN_PASSWORD=xxxxx
    ENV ASPIRE_MAVEN_PASSWORD=$ASPIRE_MAVEN_PASSWORD

    ARG ASPIRE_LOG_DIR=/aspire/logs
    ENV ASPIRE_LOG_DIR=$ASPIRE_LOG_DIR

  5. Update / upgrade /wget / unzip
    RUN apk update && apk upgrade && apk add wget && apk add unzip

  6. add aspire user and group
    RUN addgroup -g 1000 -S aspire && adduser -u 1000 -S aspire -G aspire

  7. set to run as root temporarily
    USER root

  8. set working directory to "aspire"
    WORKDIR /aspire

  9. download aspire from repository
    RUN wget --user=${ASPIRE_MAVEN_USERNAME} --password=${ASPIRE_MAVEN_PASSWORD} https://repository.searchtechnologies.com/artifactory/public/com/searchtechnologies/aspire/binaries/3.2/aspire-distribution-3.2-binaries.zip -P /aspire

  10. Add the run script to /aspire directory
    ADD run.sh ./

  11. Add the custom maven repository
    ADD maven-repository ./

  12. Unzip the aspire distribution
    RUN unzip ./aspire-distribution-3.2-binaries.zip

  13. Copy over custom aspire.sh script which needs to be run instead
    RUN rm ./aspire-distribution-3.2/bin/aspire.sh
    ADD aspire.sh ./aspire-distribution-3.2/bin

  14. Delete original aspire config folder
    RUN rm -r ./aspire-distribution-3.2/config

  15. Add the custom Aspire configuration
    ADD config ./aspire-distribution-3.2/config

  16. Set execute rights on the run script
    RUN chmod +x ./run.sh

  17. Change ownership of the /aspire folder
    RUN chown -R aspire:aspire ./

  18. Change ownership on maven repository folder
    RUN chown -R aspire:aspire ./maven-repository

  19. Remove the zip files
    RUN rm ./aspire-distribution-3.2-binaries.zip

  20. make log file
    RUN mkdir ./logs
    RUN chmod 755 ./logs

    EXPOSE $ASPIRE_ADMIN_PORT

  21. Add execute rights on the Aspire start script
    RUN chmod +x /aspire/aspire-distribution-3.2/bin/aspire.sh

  22. Update specific environment values in Aspire settings.xml file
    RUN sed -i "s|##MONGODB_URI##|$ASPIRE_MONGODB_URI|g" /aspire/aspire-distribution-3.2/config/settings.xml
    RUN sed -i "s|##MAVEN_REPOSITORY##|$ASPIRE_MAVEN_REPOSITORY|g" /aspire/aspire-distribution-3.2/config/settings.xml
    RUN sed -i "s|##ZOOKEEPER_URI##|$ASPIRE_ZOOKEEPER_URI|g" /aspire/aspire-distribution-3.2/config/settings.xml
    RUN sed -i "s|##JAVA_MAX_MEMORY##|$JAVA_MAX_MEMORY|g" /aspire/aspire-distribution-3.2/bin/aspire.sh
    RUN sed -i "s|##JAVA_INITIAL_MEMORY##|$JAVA_INITIAL_MEMORY|g" /aspire/aspire-distribution-3.2/bin/aspire.sh

  23. change ownership of the /aspire folder
    RUN chown -R aspire:aspire ./

  24. Set to run as aspire user
    USER aspire

  25. Wiki Markup
    seem to have to give full path otherwise when you try and run it cannot find the run.sh script \\
    CMD \["sh","/aspire/run.sh"\]|
    \\
    *NOTE:* In the Dockerfile above, Aspire logs are stored locally within the container (which is ok when testing the container).  However, should a K8s pod/container fail which contains the container, then any Aspire logs will be lost and possible causes for the pod/container failing will also be lost.  The option would be to store any log files to persistent storage (K8s volume) which can then be accessed whether the pod/container is running or not.  See [https://kubernetes.io/docs/tasks/configure-pod-container/configure-volume-storage|https://kubernetes.io/docs/tasks/configure-pod-container/configure-volume-storage] for more information.
    +Run the container locally on your machine (to test)+
    In order to test your Dockerfile works as expected, you can run a series of Docker commands as shown below:

  26. Build Aspire Image – this will create an image with a name of "aspire"

    sudo docker build <path to folder containing Dockerfile> -t aspire


    Alternatively, you can pass arguments into the Dockerfile which will override the any existing variables as shown below i.e this will use a different username/password combination to download Aspire and also reference a local version of MongoDB:

    docker build . -t aspire \
    --build-arg [email protected] \
    --build-arg=ASPIRE_MAVEN_PASSWORD=blahblah1234! \
    --build-arg ASPIRE_MONGODB_URI=192.168.1.207:27017


  27. Run the new container

...

  1. Configure Docker to use the "gcloud" command-line tool. This authenticates requests to the Container Registry.

    gcloud auth configure-docker


  2. Tag the image with a registry name

    docker tag aspire eu.gcr.io/<PROJECT_ID>/aspire:latest


  3. Push the image to the container registry

    docker push eu.gcr.io/<PROJECT_ID>/aspire:latest


    Deploying as part of continuous integration/continuous delivery (CI/CD)
    If your project incorporates CI/CD, then using a technology such as in our case, Google Cloud Build, will allow you to have complete control over defining custom workflows for building, testing and deploying across multiple environments.
    In order to deploy the image from the container registry, a sample cloud deployment file is required as shown below (please note the reference to the username/password combination needed to download Aspire).
    Please liaise with your own DevOps resources to confirm your own requirements. The Aspire container can then be set to deploy manually or as part of an automated process in a workflow including, for example, setting the minimum/maximum number of pods and the pod machine types that get deployed.

    steps:

  • Wiki Markup
    name: "gcr.io/cloud-builders/docker" \\
        args: \\
          \[ \\
            "build", \\
            "--build-arg", \\
            "ASPIRE_MAVEN_USERNAME", \\
            "--build-arg", \\
            "ASPIRE_MAVEN_PASSWORD", \\
            "-t", \\
            "gcr.io/<PROJECT_ID>/bitbucket.org/aspire", \\
            ".", \\
          \] \\
        secretEnv: \["ASPIRE_MAVEN_USERNAME", "ASPIRE_MAVEN_PASSWORD"\] \\
     \\

  • Wiki Markup
    name: "gcr.io/cloud-builders/docker" \\
        args: \["push", "gcr.io/<PROJECT_ID>/bitbucket.org/blahblah/aspire"\] \\
     \\
    secrets: \\

  • kmsKeyName: projects/<PROJECT_ID>/locations/europe-west1/keyRings/blahblabhblah/cryptoKeys/aspire-build
    secretEnv:
    ASPIRE_MAVEN_USERNAME: CiQAXBzYgnYHKVthDeg3irhd4IY5diW0MwmZnwd9z+dg9KxfNs8SOgBT5dkb9haWWWoqTYBa+7rJdkQ4hz8c4wrdwwRm61COL5sblwsOtQ4Va5VBBQEbRq86MsZOFDp09TU=
    ASPIRE_MAVEN_PASSWORD: CiQAXBzYgqU3l4x8R1EyygiQEtKHyq8CEsDncxmzAaDZtuus+sQSMQBT5dkbeNG8w5FbkuzqPqAFqVKjYQZAGxHtCc1Q3u7zO4qAEaI4RaWedv0feynP44g=|