diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1baae81 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: bash +os: +- linux +services: +- docker +deploy: + provider: script + script: bash ./docker-build.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..33a4450 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM gcr.io/cloud-builders/docker +RUN apt-get update && \ + apt-get -y install sudo jq wget +RUN wget https://github.com/appsody/appsody/releases/download/0.2.2/appsody_0.2.2_amd64.deb +COPY setupAndRunExtract.sh . +RUN apt install -f ./appsody_0.2.2_amd64.deb \ No newline at end of file diff --git a/README.md b/README.md index dc09080..cd98e0c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -# appsody-docker -A docker image with Appsody CLI installed. Useful for running Appsody in Tekton pipelines. +# Appsody in Docker + +A builder for the `appsody/appsody-docker` Docker image, which is the `gcr.io/cloud-builders/docker` image with the Appsody CLI added to it. The image can be used within a build pipeline - such as a Tekton pipeline - to perform actions using the Appsody CLI. + +At present, the image is equipped with a script (`setupAndRunExtract.sh`) that runs the `appsody extract` command, after mounting the appropriate project source directory. The script assumes that the image is running within a Docker container in a Tekton pipeline. It discovers the `/workspace` mount point, and retrieves the host's directory corresponding to that mount. It then gives that mount point to the Appsody CLI in the `APPSODY_MOUNT_PROJECT` environment variable. This type of retrieval is necessary because the Appsody CLI runs in Docker within a Docker image. + +### Building the image +This repo includes a `.travis.yml` file that builds and pushes the image to Docker Hub. However, if you prefer building the image manually, issue the following command: + +```sh +docker build -t appsody-docker -f Dockerfile . +``` + +### Using the image +An example of usage is provided by the [Appsody Tekton pipeline example](https://github.com/appsody/tekton-example). Check out the [Appsody build task](https://github.com/appsody/tekton-example/blob/master/appsody-build-task.yaml) manifest. + +In that context, the image runs the `appsody extract` command to retrieve the entire project tree from the Appsody stack image and the application source tree hosted on GitHub. + +This image could be modified to run additional `appsody` commands if necessary. + diff --git a/docker-build.sh b/docker-build.sh new file mode 100755 index 0000000..8887d2b --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e +echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +docker build -t $DOCKER_ORG/appsody-docker . +docker push $DOCKER_ORG/appsody-docker \ No newline at end of file diff --git a/setupAndRunExtract.sh b/setupAndRunExtract.sh new file mode 100755 index 0000000..b9fff05 --- /dev/null +++ b/setupAndRunExtract.sh @@ -0,0 +1,46 @@ +#!/bin/bash +set -e +# inspecting the container to find the mounts +containerid=`docker ps|grep appsody-docker|awk '{print $1}'` +dockerinspect=`docker inspect ${containerid}` +# checking the mounts to extract the workspace mount +notdone=true +found=false +idx=0 +while [ "$notdone" = true ]; do + dest=`echo ${dockerinspect}|jq --argjson index $idx '.[] | .Mounts[$index].Destination '` + echo $dest + if [ "$dest" = "\"/workspace\"" ] ; then + source=`echo ${dockerinspect}|jq --argjson index $idx '.[] | .Mounts[$index].Source '` + found=true + notdone=false + elif [ "$dest" == null ]; then + notdone=false + fi + idx=$[$idx+1] + +done +if [ ! "$found" = true ] ; then + echo Could not find a workspace mount - something is wrong + exit 1 +else + echo Source mount is ${source} +# Removing the quotes + source="${source%\"}" + source="${source#\"}" +fi +# Appending appsody-source + postfix="/appsody-source" + source=$source$postfix +export APPSODY_MOUNT_PROJECT=${source} +echo APPSODY_MOUNT_PROJECT=${APPSODY_MOUNT_PROJECT} +# Create the /extracted sub-dir +mkdir /workspace/extracted +# Run appsody extract -v from the source directory +cd /workspace/appsody-source +ls -latr +appsody extract -v +# Copy the extracted contents to /workspace/extracted +cp -rf /builder/home/.appsody/extract/appsody-source/* /workspace/extracted/ +ls -latr /workspace/extracted +