Skip to content

Commit

Permalink
144 project skeleton (#146)
Browse files Browse the repository at this point in the history
* 137 better releases (#141)

* Automatic Github and Docker releases from Travis
* Improve documentation

* 137 better releases (#143)

* Fixes path. Fixes #137

* feat(skeleton): skeleton of the project added
Closes #144
  • Loading branch information
artdaw authored Dec 17, 2018
1 parent 21fbecf commit ad7a688
Show file tree
Hide file tree
Showing 27 changed files with 319 additions and 358 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ modules.xml

### Project ###
/skrop
docker/skrop
docker/sample.eskip
*coverage.txt
33 changes: 21 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@ dist: trusty

branches:
only:
- master
- master

env:
global:
- PROJECT_DIR=/go/src/github.com/zalando-stups/skrop
- secure: iOfz4tQ/0pV+BTnnzzh0cxVHJfw6cgO+O5Gc/48rZIt0LjjIZByvMnatUv2wWlWCM01RhFy0blMAeY7twDSNzqu39voJCZzt4HL1YW8JH9/o4veEMo6MdEpJRQczlJnHpLDRXyW+EcrSunHSE1BQwbEDCBqlISlWBnVuLrvI9en+kQIQjGylazADYkwt0Dljaz73OqEhqqW6obnz7tO4OnTtRZr+lAyQxOCRsEy7Drnc19HWIfORvsAsRnjDboof2WtDoNYYiDEnD89bpiu012OZYI+wik4p2g9fyCLUOpizTI+rLYU0a3M0D6JDmL3fehF+I/s27Hh2uh9QtU8YD2FZ4LthfqkeF1uUyuikMTWI6r1N2EZiKLhFcYezB9R8H+XcsLRwZoxWHHM6OVmkeX7v7LaJYzsNWzPU7YL3Ja1Upn+f9EsK4/mi7uupOLyNUxmOBLa6Anll+IMYor5qmo8S2ahzenREURPuBdZ1OgpheFYK9+9QkkjSCzXm1NjWp1B39a3VtQ1ZVldu7NE7PVRJSWPrfi3YBlcs8qxz54GoAo2yCyPTka12iissVULWQF+fr2NuE2YEPBBZdmi+wHTCZ18V7ts3W8ww7o9ZkAPT9vDKsWVzqe1RmR6Dv+0ocYNVIpyOyL0exHFqujRtbMg4STY6zPaaibcs3bafIq8=
- IMAGE_NAME=skrop/skrop
- PROJECT_DIR=/go/src/github.com/zalando-stups/skrop
- secure: iOfz4tQ/0pV+BTnnzzh0cxVHJfw6cgO+O5Gc/48rZIt0LjjIZByvMnatUv2wWlWCM01RhFy0blMAeY7twDSNzqu39voJCZzt4HL1YW8JH9/o4veEMo6MdEpJRQczlJnHpLDRXyW+EcrSunHSE1BQwbEDCBqlISlWBnVuLrvI9en+kQIQjGylazADYkwt0Dljaz73OqEhqqW6obnz7tO4OnTtRZr+lAyQxOCRsEy7Drnc19HWIfORvsAsRnjDboof2WtDoNYYiDEnD89bpiu012OZYI+wik4p2g9fyCLUOpizTI+rLYU0a3M0D6JDmL3fehF+I/s27Hh2uh9QtU8YD2FZ4LthfqkeF1uUyuikMTWI6r1N2EZiKLhFcYezB9R8H+XcsLRwZoxWHHM6OVmkeX7v7LaJYzsNWzPU7YL3Ja1Upn+f9EsK4/mi7uupOLyNUxmOBLa6Anll+IMYor5qmo8S2ahzenREURPuBdZ1OgpheFYK9+9QkkjSCzXm1NjWp1B39a3VtQ1ZVldu7NE7PVRJSWPrfi3YBlcs8qxz54GoAo2yCyPTka12iissVULWQF+fr2NuE2YEPBBZdmi+wHTCZ18V7ts3W8ww7o9ZkAPT9vDKsWVzqe1RmR6Dv+0ocYNVIpyOyL0exHFqujRtbMg4STY6zPaaibcs3bafIq8=
- secure: Yl4Wj4v8mw5jTioaLCtg6V9lS/9kxNLXHqKldZkfzcYstvqKZddDzG++FUgZ7UUVI3oaozU6sx8VnQR7mrpJWstt4fliekNyr1mCxTXrp4VK3CmcRWk7li+hnRL5707t08L6z2mqJ8ZI9H9VvdyJPTKs3mF+BzE5jU5W6sOIFrWsT0TK9vpJJJZB25eEE8G140CB3vaXXOUinwadVkBnifBlxR4tEBfYNOK4YfM7g4oZuamljMtZ16uE0qibpk5L9D6Y2i6s4utFjybk+S0VqvQCrF5+re2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h3jHoXhKP7w=

script:
- docker run -t -v $(pwd):$PROJECT_DIR skrop/skrop-build sh -c "cd $PROJECT_DIR && ./.travis/test.sh"
- docker run -t -v $(pwd):$PROJECT_DIR skrop/skrop-build sh -c "cd $PROJECT_DIR && ./.travis/test-with-coverage.sh"
- ./.travis/git-tag.sh

after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)

deploy:
provider: releases
skip_cleanup: true
api_key:
secure: BmWHMRbpd3gpOOkn85bRtNzRMCIE4hRO6I/AbhHo/sCv4pay1cXCkWdYMRTkxeLyUg6Ilyx9YVuUFG+tO84el41aaEqhShUGueBTLS8eLALoWcxU6LWE6+VNLFD5kjWd/UllithQ0uPRX1bbcIcmadAMZjhdxCC6pBCdbI7S7YGPby3vbzawPQBAkx17Rmo39/t67zN5gr8KWFltuvlVt6cK6TfC0C4r5jQaqZ49p4NrFJHY1/Rc9+z925zGM0WJ3E9CGH3xRvx5E/0u9l72b2b5iLrMnQzV91G7ZlsVrZqnoAvGgX8Cdw1yJRvC+3RxhCP+dqB3yZFrmDmGuyheNjyf1VOUl9jUnTyY6xAePS+7+Z++gnUv9VzSvW1JFR3iNrc25FsetHIsxaAYnbEsfG5wmSq1jrSHzl7kofaPHbhDvdh4m2xmp19c+8upFyugUnHPwXfIk78/0hqtWbo813MCyaC9Z/FEQPwA0e5lONGBcFemqCRaF9cZRrgBmi/HqB2S/Wcp33lorv4pxKA0frJ930o/RUoCC6kUnSrZQNRwCW2PqdV99E2GpRFJQ9Cq+0VSFX/jB1l8SFOrDIOuXPcPef7JWqCwksoFgIez6o9BO3MREp3QiZicqUS3Bkgsp8tWNdOTtmjDTh16Z6Elz83bvP1ba6gqrzLTDCJY06I=
on:
repo: zalando-stups/skrop
tags: true
- provider: script
script: ./docker/docker-release.sh
on:
repo: zalando-stups/skrop
branch: master
- provider: releases
skip_cleanup: true
api_key:
secure: BmWHMRbpd3gpOOkn85bRtNzRMCIE4hRO6I/AbhHo/sCv4pay1cXCkWdYMRTkxeLyUg6Ilyx9YVuUFG+tO84el41aaEqhShUGueBTLS8eLALoWcxU6LWE6+VNLFD5kjWd/UllithQ0uPRX1bbcIcmadAMZjhdxCC6pBCdbI7S7YGPby3vbzawPQBAkx17Rmo39/t67zN5gr8KWFltuvlVt6cK6TfC0C4r5jQaqZ49p4NrFJHY1/Rc9+z925zGM0WJ3E9CGH3xRvx5E/0u9l72b2b5iLrMnQzV91G7ZlsVrZqnoAvGgX8Cdw1yJRvC+3RxhCP+dqB3yZFrmDmGuyheNjyf1VOUl9jUnTyY6xAePS+7+Z++gnUv9VzSvW1JFR3iNrc25FsetHIsxaAYnbEsfG5wmSq1jrSHzl7kofaPHbhDvdh4m2xmp19c+8upFyugUnHPwXfIk78/0hqtWbo813MCyaC9Z/FEQPwA0e5lONGBcFemqCRaF9cZRrgBmi/HqB2S/Wcp33lorv4pxKA0frJ930o/RUoCC6kUnSrZQNRwCW2PqdV99E2GpRFJQ9Cq+0VSFX/jB1l8SFOrDIOuXPcPef7JWqCwksoFgIez6o9BO3MREp3QiZicqUS3Bkgsp8tWNdOTtmjDTh16Z6Elz83bvP1ba6gqrzLTDCJY06I=
on:
repo: zalando-stups/skrop
tags: true
18 changes: 18 additions & 0 deletions .travis/git-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

. docker/version.sh

echo "TRAVIS_BRANCH=${TRAVIS_BRANCH}"
echo "TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}"
echo "GITHUB_AUTH=${GITHUB_AUTH}"

if [ "${TRAVIS_BRANCH}_${TRAVIS_PULL_REQUEST}" = "master_false" ]; then
echo "Merge to 'master'. Tagging patch version up."
git config --global user.email "[email protected]"
git config --global user.name "Travis CI"
echo "Creating tag for version: ${NEXT_PATCH_VERSION}"
git tag ${NEXT_PATCH_VERSION} -a -m "Generated tag from TravisCI for build ${TRAVIS_BUILD_NUMBER}"
git push -q --tags https://$GITHUB_AUTH@github.com/zalando-stups/skrop
else
echo "Not a merge to 'master'. Don't release a new version."
fi
File renamed without changes.
52 changes: 4 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,18 @@
routes_file ?= ./eskip/sample.eskip
docker_tag ?= skrop/skrop

CURRENT_VERSION = $(shell git describe --tags --always --dirty)
VERSION ?= $(CURRENT_VERSION)
NEXT_PATCH = $(shell go run packaging/version/version.go patch $(CURRENT_VERSION))
COMMIT_HASH = $(shell git rev-parse --short HEAD)


build:
go build ./cmd/skrop
./docker/skrop-build.sh

docker:
./packaging/build.sh $(VERSION) $(routes_file) $(docker_tag)
./docker/docker-build.sh

docker-run:
rm -rf "$$(pwd)"/mylocalfilecache
mkdir "$$(pwd)"/mylocalfilecache
docker run --rm -v "$$(pwd)"/images:/images -v "$$(pwd)"/mylocalfilecache:/mylocalfilecache -e STRIP_METADATA='TRUE' -p 9090:9090 skrop/skrop -verbose

test: build test-only
./docker/docker-run.sh

test-only:
test:
go test ./...

init-deps:
./packaging/build.sh
go get ./cmd/skrop/

all: init-deps build test

tag:
echo "Creating tag for version: $(VERSION)"
git tag $(VERSION) -a -m "Generated tag from TravisCI for build $(TRAVIS_BUILD_NUMBER)"

push-tags:
git push -q --tags https://$(GITHUB_AUTH)@github.com/zalando-stups/skrop

release-patch:
echo "Incrementing patch version"
make VERSION=$(NEXT_PATCH) tag push-tags

ci-user:
git config --global user.email "[email protected]"
git config --global user.name "Travis CI"

ci-release-patch: ci-user release-patch

ci-test:
./.travis/test.sh

ci-trigger: ci-test
ifeq ($(TRAVIS_BRANCH)_$(TRAVIS_PULL_REQUEST), master_false)
echo "Merge to 'master'. Tagging patch version up."
make ci-release-patch
else
echo "Not a merge to 'master'. Not versionning this merge."
endif

build-docker-vips:
docker build -f Dockerfile-Vips --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --build-arg VCS_REF=`git rev-parse --short HEAD` -t skrop/alpine-mozjpeg-vips:3.3.1-8.7.0 .
docker push skrop/alpine-mozjpeg-vips:3.3.1-8.7.0
67 changes: 6 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,19 @@ Skrop is a media service based on [Skipper](https://github.com/zalando/skipper)
In order to be able to use Skrop, you have to be familiar with how
[Skipper](https://github.com/zalando/skipper) works.

### Getting started

Skrop is 'go get' compatible. If needed, create a Go workspace first:

mkdir ~/go-workspace
cd ~/go-workspace
export GOPATH=$(pwd)

This can be set up in the BASH profile (`~/.bash_profile` or `~/.bashrc`)

export GOPATH=~/go-workspace

Get the Skrop sources:

go get github.com/zalando-stups/skrop

### Install dependencies:

#### System dependencies
* [Install](./docs/INSTALL.md)
* [Build from sources](./docs/INSTALL.md#build-from-sources)
* [Install dependencies](./docs/INSTALL.md#install-dependencies)
* [Using Docker](./docs/INSTALL.md#using-docker)
* [Using Heroku](./docs/INSTALL.md#using-heroku)

The [vips](https://github.com/jcupitt/libvips) library needs to be installed for Skrop to build.

On macOS, that can be easily done using `brew`.

```bash
brew install vips
```

On a Linux machine, use the provided script.

```bash
run packaging/install-vips.sh
```

#### GO dependencies

Skrop uses [modules](https://github.com/golang/go/wiki/Modules), so make sure to have go 1.11+ and just run
```
export GO111MODULE=on
./packaging/build.sh
go get ./cmd/skrop/
```
### Getting started

### Run Skrop
```
go run cmd/skrop/main.go -routes-file eskip/sample.eskip -verbose
```

### Demo

Press here to deploy your own demo on Heroku

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/zalando-stups/skrop)

### Test

```
Expand Down Expand Up @@ -131,20 +90,6 @@ environment variable to the running system:
STRIP_METADATA=TRUE
```

## Packaging
In order to package skrop for production, you're going to need [Docker](https://docs.docker.com).
To build a Docker image, just run the build script (the arguments are optional):

```
make docker version=1.0.0 routes_file=eskip/sample.eskip docker_tag=zalando-stups/skrop
```

Now you can start Skrop in a Docker container:

```
make docker-run
```

## Continuous Integration

We are using [_Travis CI_](https://travis-ci.org/zalando-stups/skrop) for this project.
Expand Down
21 changes: 1 addition & 20 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
# build stage
FROM golang:1.11.1-alpine AS build-env

ENV GOPATH /go
ENV GOOS linux

RUN apk add --update git bash

ADD packaging/install-vips.sh install-vips.sh
RUN ./install-vips.sh

ADD . /go/src/github.com/zalando-stups/skrop
WORKDIR /go/src/github.com/zalando-stups/skrop

ENV GO111MODULE on

RUN go build ./cmd/skrop

# final stage
FROM skrop/alpine-mozjpeg-vips:3.3.1-8.7.0

ARG ROUTES_FILE
Expand All @@ -34,7 +15,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"

COPY --from=0 /go/src/github.com/zalando-stups/skrop/skrop /usr/local/bin/
ADD skrop /usr/local/bin/
ADD $ROUTES_FILE skrop.eskip

ENTRYPOINT skrop -routes-file skrop.eskip ${SKROP_ARGS}
File renamed without changes.
25 changes: 25 additions & 0 deletions docker/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

readonly ROUTES_FILE=${1-"./sample.eskip"}
readonly IMAGE_NAME=${2-"skrop/skrop"}

. docker/version.sh

function build_docker_image() {
docker pull "$IMAGE_NAME" || true
docker build --pull --cache-from "$IMAGE_NAME" \
--build-arg ROUTES_FILE=${ROUTES_FILE} \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg VERSION=${NEXT_PATCH_VERSION} \
-t ${IMAGE_NAME} ./docker \
&& return 0
}

echo >&2 "Building Docker image…"
build_docker_image
if [ "$?" -ne 0 ]; then
echo >&2 "Aborting!"
exit 1
fi
echo >&2 "Docker image build successfully…"
29 changes: 29 additions & 0 deletions docker/docker-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

readonly IMAGE_NAME=${1-"skrop/skrop"}

. docker/version.sh

./docker/skrop-build.sh

cp skrop ./docker
cp ./eskip/sample.eskip ./docker

./docker/docker-build.sh

echo >&2 "Tagging Docker images…"

docker tag "$IMAGE_NAME" "${IMAGE_NAME}:latest"
docker tag "$IMAGE_NAME" "${IMAGE_NAME}:${NEXT_PATCH_VERSION}"

echo >&2 "Logging in to Docker Hub…"

echo "$DOCKER_USERNAME"
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin

echo >&2 "Pushing Docker images…"

docker push "${IMAGE_NAME}:latest"
docker push "${IMAGE_NAME}:${NEXT_PATCH_VERSION}"

echo >&2 "Success!"
5 changes: 5 additions & 0 deletions docker/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

rm -rf "$$(pwd)"/mylocalfilecache
mkdir "$$(pwd)"/mylocalfilecache
docker run --rm -v "$$(pwd)"/images:/images -v "$$(pwd)"/mylocalfilecache:/mylocalfilecache -e STRIP_METADATA='TRUE' -p 9090:9090 skrop/skrop -verbose
13 changes: 13 additions & 0 deletions docker/skrop-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

PROJECT_DIR="/go/src/github.com/zalando-stups/skrop"

docker pull skrop/skrop-build
docker run -t -v $(pwd):${PROJECT_DIR} skrop/skrop-build sh -c "cd ${PROJECT_DIR} && go build ./cmd/skrop"

if [ "$?" -ne 0 ]; then
echo >&2 "Error building Skrop. Aborting!"
exit 1
fi

echo >&2 "Skrop executable was successfully built!"
6 changes: 6 additions & 0 deletions docker/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

export CURRENT_VERSION="$(git describe --tags --always)"
echo "CURRENT_VERSION=${CURRENT_VERSION}"
export NEXT_PATCH_VERSION="$(go run docker/version/version.go patch ${CURRENT_VERSION})"
echo "NEXT_PATCH_VERSION=${NEXT_PATCH_VERSION}"
File renamed without changes.
Loading

0 comments on commit ad7a688

Please sign in to comment.