Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Build in kubekite #660

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3552b00
Initial commit of AWS request signing support
chrissnell Feb 20, 2018
af10c4a
Initial attempt at Dockerized build
chrissnell Feb 20, 2018
601301f
Merge pull request #1 from webflow/aws-signing
chrissnell Feb 20, 2018
0177e16
Merge pull request #2 from webflow/docker-build
chrissnell Feb 20, 2018
9101626
Add Buildkite instrumentation
chrissnell Feb 21, 2018
e4d1b49
Create build directory if it doesn't exist
chrissnell Feb 21, 2018
89fd553
Correct build path
chrissnell Feb 21, 2018
a87ed32
First attempt at a two-part Buildkite build
chrissnell Feb 22, 2018
4559b53
Add wait between build steps
chrissnell Feb 22, 2018
397780f
Tweak the pipeline
chrissnell Feb 22, 2018
30a2bb5
Fix broken IMAGE_NAME
chrissnell Feb 22, 2018
0e711c7
Fix broken Dockerfile file name
chrissnell Feb 22, 2018
3867825
typo
chrissnell Feb 22, 2018
b5632d4
A new entrypoint script for oauth2_proxy
chrissnell Feb 22, 2018
57ae49b
Add LICENSE file for entrypoint script
chrissnell Feb 22, 2018
2d82ea7
chmod 755 /entrypoint.sh
chrissnell Feb 23, 2018
15741e1
Add gosu to image and use it to run oauth2_proxy
chrissnell Feb 23, 2018
b38cfb9
Also install curl
chrissnell Feb 23, 2018
1b3d580
Have curl save to arch-less filename
chrissnell Feb 23, 2018
a2115a6
Use absolute path for gosu
chrissnell Feb 23, 2018
fd2f6c4
Creat conf/ directory if it doesn't exist
chrissnell Feb 23, 2018
18aecd4
Prefix binary with /
chrissnell Feb 23, 2018
732da5f
Make oauth2_proxy executable
chrissnell Feb 24, 2018
8aaf484
don't pass --config to oauth2_proxy
chrissnell Feb 24, 2018
def9765
List contents of /conf for debugging
chrissnell Feb 24, 2018
db58ec4
Don't create /conf
chrissnell Feb 24, 2018
f762a4d
Rework entrypoint script
chrissnell Feb 24, 2018
d568e81
Test if HTTPS_ADDRESS is nil
chrissnell Mar 6, 2018
9578d21
Add quotes around -email-domain param value
chrissnell Mar 6, 2018
a119fba
Properly quote and test for all variables
chrissnell Mar 6, 2018
4ffc602
Echo launch command to stdout
chrissnell Mar 6, 2018
2cad887
Report some helpful debugging info if launch fails
chrissnell Mar 6, 2018
7ed0efc
Only quote args for email domain
chrissnell Mar 7, 2018
b263df3
Only quote args for email domain
chrissnell Mar 7, 2018
cecb1d2
Disable globbing in entrypoint script
chrissnell Mar 9, 2018
b6fba9b
De-quote email domains
chrissnell Mar 9, 2018
df694f7
Add some debugging to entrypoint script
chrissnell Mar 11, 2018
d742083
Export AWS keys
chrissnell Mar 11, 2018
6376c3c
Add some debugging to print requests as they come through
chrissnell Mar 11, 2018
ecb33fc
Re-order building of arguments in entrypoint
chrissnell Mar 11, 2018
c604189
Don't set unneeded GAP headers
chrissnell Mar 11, 2018
74db9d4
Add optional cookie security flag
chrissnell Mar 11, 2018
091683e
Send actual signed request
chrissnell Mar 11, 2018
9f9d7b2
Print request headers as debugging aid
chrissnell Mar 11, 2018
4b3b652
Debug body, don't change Connection header
chrissnell Mar 11, 2018
495bc9e
Remove Referrer and XFF headers
chrissnell Mar 11, 2018
827937a
Cleanup
chrissnell Mar 11, 2018
bd2bba5
Do not sign requests if a signing region was not passed
chrissnell Sep 4, 2018
e85bd8f
Update dependiency locks
chrissnell Sep 4, 2018
2093172
Speed up build (no upx) and add gpg
chrissnell Sep 4, 2018
88b2596
Don't remove GPGHOME stuff because it doesn't exist
chrissnell Sep 4, 2018
f9f2b30
Build in kubekite
chrissnell Oct 16, 2018
9d2e239
add missing escape
chrissnell Oct 16, 2018
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
38 changes: 38 additions & 0 deletions .buildkite/build-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -eo pipefail

# Determine the image and cache tags
IMAGE_TAG=${BUILDKITE_BRANCH}
CACHE_TAG=${IMAGE_TAG}

# Set IMAGE_NAME to something intermediate
IMAGE_NAME="oauth2_proxy-intermediate"

# Determine the Dockerfile location
if [ -z "$DOCKERFILE" ]; then
DOCKERFILE="Dockerfile-buildbinary"
fi

if [ ! -d build/public ]; then
mkdir -p build/public
fi

git log -1 > build/public/REVISION.txt

# Build the new image
docker build \
--network host \
--cache-from $IMAGE_NAME:$CACHE_TAG \
--tag $IMAGE_NAME:$IMAGE_TAG \
$EXTRA_TAGS \
-f $DOCKERFILE \
.

# Execute the image so that we can get the binary out of it
docker run $IMAGE_NAME:$IMAGE_TAG

# Copy the binary from the container
docker container cp $(docker ps -ql):/go/src/github.com/webflow/oauth2_proxy/oauth2_proxy .

# Upload the binary as a Buildkite build artifact
buildkite-agent artifact upload oauth2_proxy
61 changes: 61 additions & 0 deletions .buildkite/build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
set -eo pipefail

# Determine the image and cache tags
IMAGE_TAG=${BUILDKITE_BRANCH}
CACHE_TAG=${IMAGE_TAG}

# Determine the Dockerfile location
if [ -z "$DOCKERFILE" ]; then
DOCKERFILE="Dockerfile-buildimage"
fi

eval $(aws ecr get-login --no-include-email --region us-east-1)

# Pull the latest branch tag for caching, if it exists
IMAGE_EXISTS=1
docker pull $IMAGE_NAME:$IMAGE_TAG || IMAGE_EXISTS=0

# If the branch image didn't already exist, pull the latest
if [ $IMAGE_EXISTS -eq 0 ]; then
docker pull $IMAGE_NAME:latest || true
CACHE_TAG=latest
fi

EXTRA_TAGS="--tag $IMAGE_NAME:$BUILDKITE_COMMIT"

# If the branch is master, also tag with latest
if [[ "$IMAGE_TAG" == "master" ]]; then
EXTRA_TAGS="$EXTRA_TAGS --tag $IMAGE_NAME:latest"
fi

if [ ! -d build/public ]; then
mkdir -p build/public
fi

git log -1 > build/public/REVISION.txt

# Retrieve our artifact
buildkite-agent artifact download oauth2_proxy .

# Build the new image
docker build \
--network host \
--cache-from $IMAGE_NAME:$CACHE_TAG \
--tag $IMAGE_NAME:$IMAGE_TAG \
$EXTRA_TAGS \
-f $DOCKERFILE \
.

# Push to the repository
docker push $IMAGE_NAME:$IMAGE_TAG
echo "Pushing docker image to ECR: $IMAGE_NAME:$IMAGE_TAG"

docker push $IMAGE_NAME:$BUILDKITE_COMMIT
echo "Pushing docker image to ECR: $IMAGE_NAME:$BUILDKITE_COMMIT"

# If the branch is master, also push the latest tag
if [[ "$IMAGE_TAG" == "master" ]]; then
docker push $IMAGE_NAME:latest
echo "Pushing docker image to ECR: $IMAGE_NAME:latest"
fi
15 changes: 15 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
steps:
- label : ":oauth2_proxy: Build Binary"
command: "./.buildkite/build-binary.sh"
agents:
queue: 'autoscaling-build-cluster'

- wait

- label: ":oauth2_proxy: Build Image"
command: "./.buildkite/build-image.sh"
env:
IMAGE_NAME: 024376647576.dkr.ecr.us-east-1.amazonaws.com/oauth2_proxy
AWS_ECR_LOGIN: true
agents:
queue: 'autoscaling-build-cluster'
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:latest as builder

# Install dep
RUN go get -u github.com/golang/dep/cmd/dep

# Install upx, a Linux binary compression util
RUN apt-get update && apt-get install -y upx

WORKDIR /go/src
COPY . github.com/webflow/oauth2_proxy
WORKDIR /go/src/github.com/webflow/oauth2_proxy

# Load pinned dependencies into vendor/
RUN dep ensure -v

# Build and strip our binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X main.Version=`git log --pretty=format:'%h' -n 1`" -a -installsuffix cgo -o oauth2_proxy .

# Compress the binary with upx
RUN upx oauth2_proxy

FROM ubuntu

RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y dist-upgrade

# Copy the binary over from the builder image
COPY --from=builder /go/src/github.com/webflow/oauth2_proxy/oauth2_proxy /

# Run our entrypoint script when the container is executed
CMD ["/oauth2_proxy"]
14 changes: 14 additions & 0 deletions Dockerfile-buildbinary
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:latest

# Install dep
RUN go get -u github.com/golang/dep/cmd/dep

WORKDIR /go/src
COPY . github.com/webflow/oauth2_proxy
WORKDIR /go/src/github.com/webflow/oauth2_proxy

# Load pinned dependencies into vendor/
RUN dep ensure -v

# Build and strip our binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X main.Version=`git log --pretty=format:'%h' -n 1`" -a -installsuffix cgo -o oauth2_proxy .
28 changes: 28 additions & 0 deletions Dockerfile-buildimage
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu

ENV GOSU_VERSION 1.10

RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y dist-upgrade && \
apt-get install -y curl gnupg && \
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" && \
curl -L -o /gosu "https://github.com/tianon/gosu/releases/download/1.10/gosu-${dpkgArch}" && \
curl -L -o /gosu.asc "https://github.com/tianon/gosu/releases/download/1.10/gosu-${dpkgArch}.asc" && \
export GNUPGHOME="$(mktemp -d)" && \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && \
gpg --batch --verify /gosu.asc /gosu && \
rm -r /gosu.asc && \
chmod +x /gosu && \
/gosu nobody true

# Copy the binary over from the builder image
COPY oauth2_proxy /
RUN chmod +x /oauth2_proxy

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

CMD ["/oauth2_proxy"]
Loading