Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding docker image and release scripts #123

Merged
merged 14 commits into from
Aug 16, 2017
56 changes: 56 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: 2
jobs:
build:
working_directory: /go/src/github.com/hootsuite/atlantis
docker:
- image: circleci/golang:1.8
environment:
TERRAFORM_VERSION: 0.10.0
steps:
- checkout
- setup_remote_docker:
reusable: true
- run: make deps
- run: make test
- run: make build-service
- run:
name: Install e2e dependencies
command: make end-to-end-deps
- run:
name: Starting atlantis server in the background
command: cd "${CIRCLE_WORKING_DIRECTORY}/e2e" && ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-token="$GITHUB_PASSWORD" --data-dir="/tmp" --log-level="debug" &> /tmp/atlantis-server.log
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we add the webhook-secret as well?

background: true
- run: sleep 2
- run:
name: Starting ngrok
command: cd "${CIRCLE_WORKING_DIRECTORY}/e2e" && ./ngrok http 4141 > /tmp/ngrok.log
background: true
- run: sleep 2
- run: echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url')' >> $BASH_ENV
- run:
name: Run e2e tests
command: make end-to-end-tests
- run:
name: Build image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
docker build -t hootsuite/atlantis:latest .
fi
- run:
name: Push image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
docker login -e "$DOCKER_EMAIL" -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
docker push hootsuite/atlantis:latest
fi
- run:
name: Tag and push version if exists
# work around until tags are properly supported
# https://discuss.circleci.com/t/git-tag-deploys-in-2-0/9493/6
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
for TAG in $(git tag --contains $CIRCLE_SHA1); do
Copy link
Collaborator

Choose a reason for hiding this comment

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

so this checks if there's a tag for this commit and if so pushes a new docker image? Doesn't this build run on master so how will there be a tag at the time that this build runs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea, so CircleCI doesn't have support for tagged events from Github. So we will merge something to master, create a tag and then rebuild on master to push the docker image.

docker tag hootsuite/atlantis:latest hootsuite/atlantis:$TAG
docker push hootsuite/atlantis:$TAG
done
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ atlantis
*.iml
.vscode
atlantis.db
output
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ assume role session with the GitHub username of the user running the Atlantis co
use the `atlantis_user` terraform variable alongside Terraform's
[built-in support](https://www.terraform.io/docs/providers/aws/#assume-role) for assume role
(see https://github.com/hootsuite/atlantis/blob/master/README.md#assume-role-session-names)
* Atlantis has a docker image now ([#123](https://github.com/hootsuite/atlantis/pull/123)). Here is how you can try it out:

```bash
docker run -it hootsuite/atlantis server --gh-user=GITHUB_USERNAME --gh-token=GITHUB_TOKEN
```

### Improvements
* Support for HTTPS cloning using GitHub username and token provided to atlantis server ([#117](https://github.com/hootsuite/atlantis/pull/117))
Expand Down
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM alpine:3.6
LABEL authors="Anubhav Mishra, Luke Kysow"
LABEL maintainer="[email protected],[email protected]"

# create atlantis user
RUN addgroup atlantis && \
adduser -S -G atlantis atlantis

ENV ATLANTIS_HOME_DIR=/home/atlantis

# install atlantis dependencies
ENV DUMB_INIT_VERSION=1.2.0
ENV GOSU_VERSION=1.10
RUN apk add --no-cache ca-certificates gnupg curl git unzip bash openssh libcap openssl && \
wget -O /bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 && \
chmod +x /bin/dumb-init && \
mkdir -p /tmp/build && \
cd /tmp/build && \
wget -O gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" && \
wget -O gosu.asc "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64.asc" && \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && \
gpg --batch --verify gosu.asc gosu && \
chmod +x gosu && \
cp gosu /bin && \
cd /tmp && \
rm -rf /tmp/build && \
apk del gnupg openssl && \
rm -rf /root/.gnupg && rm -rf /var/cache/apk/*

# install terraform binaries
ENV DEFAULT_TERRAFORM_VERSION=0.10.0

RUN AVAILABLE_TERRAFORM_VERSIONS="0.8.8 0.9.11 0.10.0" && \
for VERSION in ${AVAILABLE_TERRAFORM_VERSIONS}; do curl -LOk https://releases.hashicorp.com/terraform/${VERSION}/terraform_${VERSION}_linux_amd64.zip && \
mkdir -p /usr/local/bin/tf/versions/${VERSION} && \
unzip terraform_${VERSION}_linux_amd64.zip -d /usr/local/bin/tf/versions/${VERSION} && \
ln -s /usr/local/bin/tf/versions/${VERSION}/terraform /usr/local/bin/terraform${VERSION};rm terraform_${VERSION}_linux_amd64.zip;done && \
ln -s /usr/local/bin/tf/versions/${DEFAULT_TERRAFORM_VERSION}/terraform /usr/local/bin/terraform

# copy binary
COPY atlantis /usr/local/bin/atlantis

# copy docker entrypoint
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["server"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

just curious how big is the container in the end?

9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BUILD_ID := $(shell git rev-parse --short HEAD 2>/dev/null || echo no-commit-id)
WORKSPACE := $(shell pwd)
PKG := $(shell go list ./... | grep -v e2e | grep -v vendor | grep -v static)
IMAGE_NAME := hootsuite/atlantis

.PHONY: test

Expand Down Expand Up @@ -34,10 +35,16 @@ dist: ## Package up everything in static/ using go-bindata-assetfs so it can be
go-bindata-assetfs -pkg server static/... && mv bindata_assetfs.go server

release: ## Create packages for a release
gox -os="darwin linux" -arch="amd64"
./scripts/binary-release.sh

vendor-status:
@govendor status

fmt: ## Run goimports (which also formats)
goimports -w $$(find . -type f -name '*.go' ! -path "./vendor/*" ! -path "./server/bindata_assetfs.go")

end-to-end-deps: ## Install e2e dependencies
./scripts/e2e-deps.sh

end-to-end-tests: ## Run e2e tests
./scripts/e2e.sh
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [Locking](#locking)
* [Approvals](#approvals)
* [Production-Ready Deployment](#production-ready-deployment)
* [Docker](#docker)
* [Server Configuration](#server-configuration)
* [AWS Credentials](#aws-credentials)
* [Glossary](#glossary)
Expand Down Expand Up @@ -258,6 +259,41 @@ $ atlantis server --atlantis-url $URL --gh-user $USERNAME --gh-token $TOKEN --gh
Atlantis is now running!
**We recommend running it under something like Systemd or Supervisord.**

### Docker
Copy link
Collaborator

Choose a reason for hiding this comment

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

add to the outline at the top

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!

Atlantis also ships inside a docker image with Terraform versions `0.8.8`, `0.9.11` and `0.10.0`. Run the docker image:

```bash
docker run hootsuite/atlantis server --gh-user=GITHUB_USERNAME --gh-token=GITHUB_TOKEN
```

#### Usage
If you would like to add things like [AWS credential files](http://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html) to the docker image, you can do something like this:

* Create a custom docker file
```bash
vim Dockerfile-custom
```

```dockerfile
FROM hootsuite/atlantis

# copy aws credentials
COPY credentials /home/atlantis/.aws/credentials
```

* Build docker image

```bash
docker build -t {YOUR_DOCKER_ORG}/atlantis-custom -f Dockerfile-custom
```

* Run docker image

```bash
docker run {YOUR_DOCKER_ORG}/atlantis-custom server --gh-user=GITHUB_USERNAME --gh-token=GITHUB_TOKEN
```


### Testing Out Atlantis

If you'd like to test out Atlantis before running it on your own repositories you can fork our example repo.
Expand Down
37 changes: 0 additions & 37 deletions circle.yml

This file was deleted.

31 changes: 31 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/dumb-init /bin/sh
set -e

# Modified: https://github.com/hashicorp/docker-consul/blob/2c2873f9d619220d1eef0bc46ec78443f55a10b5/0.X/docker-entrypoint.sh

# If the user is trying to run atlantis directly with some arguments, then
# pass them to atlantis.
if [ "${1:0:1}" = '-' ]; then
set -- atlantis "$@"
fi

# Look for atlantis subcommands.
if atlantis --help "$1" 2>&1 | grep -q "atlantis $1"; then
# We can't use the return code to check for the existence of a subcommand, so
# we have to use grep to look for a pattern in the help output.
set -- atlantis "$@"
fi

# If we are running atlantis, make sure it executes as the proper user.
if [ "$1" = 'atlantis' ]; then
# If requested, set the capability to bind to privileged ports before
# we drop to the non-root user. Note that this doesn't work with all
# storage drivers (it won't work with AUFS).
if [ ! -z ${ATLANTIS_ALLOW_PRIVILEGED_PORTS+x} ]; then
setcap "cap_net_bind_service=+ep" /bin/atlantis
fi

set -- gosu atlantis "$@"
fi

exec "$@"
1 change: 0 additions & 1 deletion e2e/secrets-envs

This file was deleted.

44 changes: 44 additions & 0 deletions scripts/binary-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# define architecture we want to build
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
XC_OS=${XC_OS:-linux darwin}
XC_EXCLUDE_OSARCH="!darwin/arm !darwin/386"

# clean up
echo "-> running clean up...."
rm -rf output/*

if ! which gox > /dev/null; then
echo "-> installing gox..."
go get -u github.com/mitchellh/gox
fi

# build
# we want to build statically linked binaries
export CGO_ENABLED=0
echo "-> building..."
gox \
-os="${XC_OS}" \
-arch="${XC_ARCH}" \
-osarch="${XC_EXCLUDE_OSARCH}" \
-output "output/{{.OS}}_{{.Arch}}/atlantis" \
.

# Zip and copy to the dist dir
echo ""
echo "Packaging..."
for PLATFORM in $(find ./output -mindepth 1 -maxdepth 1 -type d); do
OSARCH=$(basename ${PLATFORM})
echo "--> ${OSARCH}"

pushd $PLATFORM >/dev/null 2>&1
zip ../atlantis_${OSARCH}.zip ./*
popd >/dev/null 2>&1
done

echo ""
echo ""
echo "-----------------------------------"
echo "Output:"
ls -alh output/
22 changes: 0 additions & 22 deletions scripts/build.sh

This file was deleted.

12 changes: 8 additions & 4 deletions scripts/e2e-deps.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#!/usr/bin/env bash

echo "Preparing to run e2e tests"
mv atlantis ${WORKDIR}/e2e/
if [ ! -f atlantis ]; then
echo "atlantis binary not found. exiting...."
exit 1
fi
mv atlantis ${CIRCLE_WORKING_DIRECTORY}/e2e/

# cd into e2e folder
cd e2e/
# Decrypting secrets for atlantis runtime: https://github.com/circleci/encrypted-files
openssl aes-256-cbc -d -in secrets-envs -k $KEY >> ~/.circlerc
# Download terraform
curl -LOk https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /home/ubuntu/bin
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
chmod +x terraform
cp terraform /go/bin/
# Download ngrok to create a tunnel to expose atlantis server
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
Expand Down
2 changes: 2 additions & 0 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
set -euo pipefail
IFS=$'\n\t'

cd e2e/

# Download dependencies
echo "Running 'make deps'"
make deps
Expand Down