Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Initial code drop (#1)
Browse files Browse the repository at this point in the history
* Initial code drop

* Added readme and .travis.yml

* Made docker org an env var.

* added a deploy phase

* Adjusted deploy phase
  • Loading branch information
chilanti authored and kylegc committed Jul 1, 2019
1 parent beaba8d commit cabf2fc
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: bash
os:
- linux
services:
- docker
deploy:
provider: script
script: bash ./docker-build.sh
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

5 changes: 5 additions & 0 deletions docker-build.sh
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions setupAndRunExtract.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cabf2fc

Please sign in to comment.