Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
Expand Down
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
env:
global:
- SQLALCHEMY_DATABASE_URI="sqlite:///:memory:"
- IMAGE_NAME=resources-api
- DEPLOY_BRANCHES="master"
language: python
sudo: required
dist: xenial
Expand Down Expand Up @@ -36,4 +38,5 @@ script:
after_script:
- docker-compose run resources-api coverage xml
- docker-compose -f docker-compose.yml down
- if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then ./cc-test-reporter -r 147d129d98f3d606ce69bc151bbeded40dc684fe11e0f5a831f11f6b36680b22 after-build --exit-code $TRAVIS_TEST_RESULT; fi
- if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then ./cc-test-reporter -r 147d129d98f3d606ce69bc151bbeded40dc684fe11e0f5a831f11f6b36680b22 after-build --exit-code $TRAVIS_TEST_RESULT; fi
- bash bin/run.sh
8 changes: 8 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -eu
# import util functions
source "${SCRIPTDIR}/../lib/util.sh"

echo "Building Docker image..."
runCommand "docker build -t $IMAGE_NAME -f Dockerfile ." || exit $?
25 changes: 25 additions & 0 deletions bin/publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# Publishes the most recent web container to docker hubs repo.
# This script assumes docker push works.
# You must set up docker push on your own.

set -eu

DOCKER_REPO="operationcode/resources-api"

IMAGE_ID=$(docker images $IMAGE_NAME:latest --format "{{.ID}}")

if [ -n "$DOCKER_USERNAME" ]; then echo "Found username"; fi
if [ -n "$DOCKER_PASSWORD" ]; then echo "Found password"; fi

if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
echo "Logging in using ENV creds"
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
fi

echo "Pushing image $IMAGE_NAME:$TRAVIS_BRANCH"
docker tag $IMAGE_ID $DOCKER_REPO
docker tag $IMAGE_ID ${DOCKER_REPO}:${TRAVIS_BUILD_NUMBER}
docker push $DOCKER_REPO
docker push ${DOCKER_REPO}:${TRAVIS_BUILD_NUMBER}
38 changes: 38 additions & 0 deletions bin/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Only process first job in matrix (TRAVIS_JOB_NUMBER ends with ".1")
if [[ ! $TRAVIS_JOB_NUMBER =~ \.1$ ]]; then
echo "Skipping deploy since it's not the first job in matrix"
exit 0
fi

# Don't process pull requests
# $TRAVIS_PULL_REQUEST will be the PR number or "false" if not a PR
if [[ -n "$TRAVIS_PULL_REQUEST" ]] && [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
echo "Skipping deploy because it's a pull request"
exit 0
fi

# Only process branches listed in DEPLOY_BRANCHES
BRANCHES_TO_DEPLOY=($DEPLOY_BRANCHES)
if [[ ! " ${BRANCHES_TO_DEPLOY[@]} " =~ " ${TRAVIS_BRANCH} " ]]; then
# whatever you want to do when arr contains value
echo "Skipping deploy, not a branch to be deployed"
exit 0
fi

if [ $? = 0 ]; then

# Get absolute path of dir where run.sh is located
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
export SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

bash ${SCRIPTDIR}/build &&
bash ${SCRIPTDIR}/publish

fi
18 changes: 18 additions & 0 deletions lib/util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

function isDryRun {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly think we could remove this entire file and not calling these wrappers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do later.

if [ "$DRYRUN" = "1" ]; then
return 0
else
return 1
fi
}

function runCommand {
if isDryRun; then
echo $1;
else
eval $1
return $?
fi
}