Skip to content

Commit

Permalink
Move to Quay; build improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sc250024 committed Aug 31, 2019
1 parent 8cbc2cf commit 5ed4436
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 59 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

1 change: 1 addition & 0 deletions .dockerignore
46 changes: 19 additions & 27 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
variables:
CI_REGISTRY: quay.io
GL_URL: github.com/rb3ckers
GO_PROJECT_NAMESPACE: trafficmirror
IMAGE_FAMILY: stackstate/trafficmirror
CI_REGISTRY: docker.io

.prep_go: &prep_go
before_script:
- echo export GO_PROJECT_PATH="$GOPATH/src/$GL_URL/$GO_PROJECT_NAMESPACE"
- export GO_PROJECT_PATH="$GOPATH/src/$GL_URL/$GO_PROJECT_NAMESPACE"
- rm -rf $GOPATH/src/$GL_URL
- mkdir -p $GOPATH/src/$GL_URL
- echo ln -s $(pwd) $GO_PROJECT_PATH
- ln -s $(pwd) $GO_PROJECT_PATH
- cd $GO_PROJECT_PATH

stages:
- build
- docker_build

go_build:
<<: *prep_go
stage: build
image: golang:1.11
image: docker:stable
script:
- go get github.com/golang/dep/cmd/dep
- dep ensure
- mkdir -p build
- env GOOS=linux GOARCH=amd64 go build -o build/trafficmirror
- ls -la $GO_PROJECT_PATH/
- docker build
--tag "${CI_REGISTRY}/${IMAGE_FAMILY}:${CI_BUILD_REF:-dirty}"
--target builder
${PWD}
- docker run
--volume ${PWD}/build:/opt/copy
--rm
--entrypoint cp
"${CI_REGISTRY}/${IMAGE_FAMILY}:${CI_BUILD_REF:-dirty}"
/build/trafficmirror /opt/copy/
artifacts:
paths:
- build
expire_in: 1 week

docker_build:
stage: docker_build
image: docker:latest
dependencies:
- go_build
services:
- docker:dind
image: docker:stable
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker build -t $IMAGE_FAMILY:${CI_BUILD_REF:-dirty} .
- echo docker push $IMAGE_FAMILY:${CI_BUILD_REF:-dirty}
- docker push $IMAGE_FAMILY:${CI_BUILD_REF:-dirty}
- echo "${quay_password}" | docker login --username=${quay_user} --password-stdin ${CI_REGISTRY}
- docker build
--tag ${CI_REGISTRY}/${IMAGE_FAMILY}:${CI_BUILD_REF:-dirty
--target app
${PWD}
- docker push "${CI_REGISTRY}/${IMAGE_FAMILY}:${CI_BUILD_REF:-dirty}"
49 changes: 44 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
FROM debian:stretch
###########
# Builder #
###########

ADD ./init.sh /init.sh
RUN chmod +x /init.sh && apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
FROM golang:1.11-alpine AS builder

ADD build/trafficmirror /trafficmirror
RUN apk add --no-cache git

CMD ["/init.sh"]
COPY . $GOPATH/src/github.com/rb3ckers/trafficmirror

WORKDIR $GOPATH/src/github.com/rb3ckers/trafficmirror

RUN set -ex \
&& go get -u -v github.com/golang/dep/cmd/dep \
&& dep ensure -v \
&& GOOS=linux GOARCH=amd64 go build -o /build/trafficmirror

RUN /build/trafficmirror --help

#######
# App #
#######

FROM alpine:latest AS app

ENV PERSISTENT_PACKAGES="ca-certificates tini"

# Copy support files
COPY rootfs /

# Upgrade OS packages for security
RUN apk upgrade --no-cache --available \
&& apk add --no-cache ${PERSISTENT_PACKAGES}

# Copy artifacts from builder container
COPY --from=builder /build/trafficmirror /trafficmirror

# Create non-root user
RUN addgroup -S -g 1000 stackstate && \
adduser -S -u 1000 -G stackstate -s /bin/sh stackstate

# Switch to non-root user
USER stackstate

EXPOSE 8080

ENTRYPOINT ["/sbin/tini", "--"]

CMD ["/docker-entrypoint.sh"]
Empty file modified build-env.sh
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions build-linux.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#! /bin/bash
env GOOS=linux GOARCH=amd64 go build
#!/bin/bash

env GOOS=linux GOARCH=amd64 go build
5 changes: 3 additions & 2 deletions build-mac.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#! /bin/bash
env GOOS=darwin GOARCH=386 go build
#!/bin/bash

env GOOS=darwin GOARCH=386 go build
22 changes: 0 additions & 22 deletions init.sh

This file was deleted.

20 changes: 20 additions & 0 deletions rootfs/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Takes these environment variables:
#
# LISTEN_PORT: port to listen on (defaults to 8080)
# MAIN: reverse proxy to this address (defaults to localhost:8888)
# USERNAME & PASSWORD: if USERNAME is set protect targets endpoint with basic auth (default to empty)

extraParams="${1}"
listenPort="${LISTEN_PORT:-8080}"
main="${MAIN:-localhost:8888}"

if [ -n "${USERNAME}" ]; then
echo "${USERNAME}:${PASSWORD}" > /password.file
extraParams="${extraParams} -password /password.file"
fi

cmd="/trafficmirror -listen ":${listenPort}" -main=${main} ${extraParams}"

exec "${cmd}"

0 comments on commit 5ed4436

Please sign in to comment.