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

Commit

Permalink
increased tests and added Codeship for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
fillup committed Feb 21, 2017
1 parent a48c4ca commit c9b5a3f
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 19 deletions.
25 changes: 13 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
FROM silintl/ubuntu:14.04
MAINTAINER Phillip Shipley <[email protected]>
FROM alpine:3.5

RUN apt-get update -y \
&& apt-get install -y \
curl \
python-setuptools \
jq \
&& easy_install pip \
&& pip install awscli
# Update APK cache
RUN apk update

COPY ecs-deploy /usr/local/bin/ecs-deploy
# Install packges needed
RUN apk add ca-certificates curl bash jq py2-pip && \
pip install awscli

RUN chmod a+x /usr/local/bin/ecs-deploy
COPY ecs-deploy /ecs-deploy
RUN chmod a+x /ecs-deploy

ENTRYPOINT ["/usr/local/bin/ecs-deploy"]
COPY test.bats /test.bats
COPY run-tests.sh /run-tests.sh
RUN chmod a+x /run-tests.sh

ENTRYPOINT ["/ecs-deploy"]
6 changes: 6 additions & 0 deletions codeship-services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ecsdeploy:
build:
image: silintl/ecs-deploy
dockerfile_path: ./Dockerfile
entrypoint: bash
command: /run-tests.sh
3 changes: 3 additions & 0 deletions codeship-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: test
service: ecsdeploy
command: /run-tests.sh
16 changes: 14 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
ecsdeploy:
image: silintl/ecs-deploy
image: ecs-deploy
env_file:
- local.env
- local.env
volumes:
- ./ecs-deploy:/ecs-deploy

test:
image: ecs-deploy
env_file:
- local.env
entrypoint: ["bash"]
command: ["/run-tests.sh"]
volumes:
- ./ecs-deploy:/ecs-deploy
- ./run-tests.sh:/run-tests.sh
11 changes: 8 additions & 3 deletions ecs-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ function getCurrentTaskDefinition() {
if [ $SERVICE != false ]; then
# Get current task definition name from service
TASK_DEFINITION_ARN=`$AWS_ECS describe-services --services $SERVICE --cluster $CLUSTER | jq -r .services[0].taskDefinition`
TASK_DEFINITION=`$AWS_ECS describe-task-definition --task-def $TASK_DEFINITION`
TASK_DEFINITION=`$AWS_ECS describe-task-definition --task-def $TASK_DEFINITION_ARN`
fi
}

function createNewTaskDefJson() {
# Get a JSON representation of the current task definition
# + Update definition to use new image name
# + Filter the def
DEF=$( echo $TASK_DEFINITION \
DEF=$( echo "$TASK_DEFINITION" \
| sed -e "s|\"image\": *\"${imageWithoutTag}:.*\"|\"image\": \"${useImage}\"|g" \
| sed -e "s|\"image\": *\"${imageWithoutTag}\"|\"image\": \"${useImage}\"|g" \
| jq '.taskDefinition' )
Expand All @@ -253,6 +253,11 @@ function createNewTaskDefJson() {

# Build new DEF with jq filter
NEW_DEF=$(echo $DEF | jq "{${NEW_DEF_JQ_FILTER}}")

# If in test mode output $NEW_DEF
if [ "$BASH_SOURCE" != "$0" ]; then
echo $NEW_DEF
fi
}

function registerNewTaskDefinition() {
Expand Down Expand Up @@ -440,7 +445,7 @@ if [ "$BASH_SOURCE" == "$0" ]; then

# Get current task definition
getCurrentTaskDefinition
echo "Current task definition: $TASK_DEFINITION";
echo "Current task definition: $TASK_DEFINITION_ARN";

# create new task definition json
createNewTaskDefJson
Expand Down
5 changes: 5 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

apk add bats --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted

bats test.bats
93 changes: 91 additions & 2 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ setup() {
[ "$output" == "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1487623908" ]
}

@test "test createNewTaskDefJson" {
TASK_DEFINITION = <<EOF
@test "test createNewTaskDefJson with single container in definition" {
imageWithoutTag="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo"
useImage="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111"
TASK_DEFINITION=$(cat <<EOF
{
"taskDefinition": {
"status": "ACTIVE",
Expand Down Expand Up @@ -206,5 +208,92 @@ setup() {
}
}
EOF
)
expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 80, "hostPort": 10080 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] } ], "networkMode": "bridge" }'
run createNewTaskDefJson
[ ! -z $status ]
[ $output == $expected ]
}

@test "test createNewTaskDefJson with multiple containers in definition" {
imageWithoutTag="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo"
useImage="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111"
TASK_DEFINITION=$(cat <<EOF
{
"taskDefinition": {
"status": "ACTIVE",
"networkMode": "bridge",
"family": "app-task-def",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
}
],
"volumes": [],
"taskDefinitionArn": "arn:aws:ecs:us-east-1:121212345678:task-definition/app-task-def:123",
"containerDefinitions": [
{
"environment": [
{
"name": "KEY",
"value": "value"
}
],
"name": "API",
"links": [],
"mountPoints": [],
"image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1487623908",
"essential": true,
"portMappings": [
{
"protocol": "tcp",
"containerPort": 80,
"hostPort": 10080
}
],
"entryPoint": [],
"memory": 128,
"command": [
"/data/run.sh"
],
"cpu": 200,
"volumesFrom": []
},
{
"environment": [
{
"name": "KEY",
"value": "value"
}
],
"name": "cache",
"links": [],
"mountPoints": [],
"image": "redis:latest",
"essential": true,
"portMappings": [
{
"protocol": "tcp",
"containerPort": 6376,
"hostPort": 10376
}
],
"entryPoint": [],
"memory": 128,
"command": [
"/data/run.sh"
],
"cpu": 200,
"volumesFrom": []
}
],
"revision": 123
}
}
EOF
)
expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 80, "hostPort": 10080 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] }, { "environment": [ { "name": "KEY", "value": "value" } ], "name": "cache", "links": [], "mountPoints": [], "image": "redis:latest", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 6376, "hostPort": 10376 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] } ], "networkMode": "bridge" }'
run createNewTaskDefJson
[ ! -z $status ]
[ $output == $expected ]
}

0 comments on commit c9b5a3f

Please sign in to comment.