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

Commit cabf2fc

Browse files
chilantikylegc
authored andcommitted
Initial code drop (#1)
* Initial code drop * Added readme and .travis.yml * Made docker org an env var. * added a deploy phase * Adjusted deploy phase
1 parent beaba8d commit cabf2fc

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: bash
2+
os:
3+
- linux
4+
services:
5+
- docker
6+
deploy:
7+
provider: script
8+
script: bash ./docker-build.sh

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM gcr.io/cloud-builders/docker
2+
RUN apt-get update && \
3+
apt-get -y install sudo jq wget
4+
RUN wget https://github.com/appsody/appsody/releases/download/0.2.2/appsody_0.2.2_amd64.deb
5+
COPY setupAndRunExtract.sh .
6+
RUN apt install -f ./appsody_0.2.2_amd64.deb

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1-
# appsody-docker
2-
A docker image with Appsody CLI installed. Useful for running Appsody in Tekton pipelines.
1+
# Appsody in Docker
2+
3+
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.
4+
5+
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.
6+
7+
### Building the image
8+
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:
9+
10+
```sh
11+
docker build -t appsody-docker -f Dockerfile .
12+
```
13+
14+
### Using the image
15+
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.
16+
17+
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.
18+
19+
This image could be modified to run additional `appsody` commands if necessary.
20+

docker-build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -e
3+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
4+
docker build -t $DOCKER_ORG/appsody-docker .
5+
docker push $DOCKER_ORG/appsody-docker

setupAndRunExtract.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e
3+
# inspecting the container to find the mounts
4+
containerid=`docker ps|grep appsody-docker|awk '{print $1}'`
5+
dockerinspect=`docker inspect ${containerid}`
6+
# checking the mounts to extract the workspace mount
7+
notdone=true
8+
found=false
9+
idx=0
10+
while [ "$notdone" = true ]; do
11+
dest=`echo ${dockerinspect}|jq --argjson index $idx '.[] | .Mounts[$index].Destination '`
12+
echo $dest
13+
if [ "$dest" = "\"/workspace\"" ] ; then
14+
source=`echo ${dockerinspect}|jq --argjson index $idx '.[] | .Mounts[$index].Source '`
15+
found=true
16+
notdone=false
17+
elif [ "$dest" == null ]; then
18+
notdone=false
19+
fi
20+
idx=$[$idx+1]
21+
22+
done
23+
if [ ! "$found" = true ] ; then
24+
echo Could not find a workspace mount - something is wrong
25+
exit 1
26+
else
27+
echo Source mount is ${source}
28+
# Removing the quotes
29+
source="${source%\"}"
30+
source="${source#\"}"
31+
fi
32+
# Appending appsody-source
33+
postfix="/appsody-source"
34+
source=$source$postfix
35+
export APPSODY_MOUNT_PROJECT=${source}
36+
echo APPSODY_MOUNT_PROJECT=${APPSODY_MOUNT_PROJECT}
37+
# Create the /extracted sub-dir
38+
mkdir /workspace/extracted
39+
# Run appsody extract -v from the source directory
40+
cd /workspace/appsody-source
41+
ls -latr
42+
appsody extract -v
43+
# Copy the extracted contents to /workspace/extracted
44+
cp -rf /builder/home/.appsody/extract/appsody-source/* /workspace/extracted/
45+
ls -latr /workspace/extracted
46+

0 commit comments

Comments
 (0)