Skip to content

Commit

Permalink
Change base image, dependency resolver and fix circle.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
pottava committed Jan 27, 2017
1 parent ca16bda commit 5c13ead
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 114 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Godeps/Readme
vendor/*
dist/*
docker-compose.override.yml

49 changes: 0 additions & 49 deletions Godeps/Godeps.json

This file was deleted.

1 change: 1 addition & 0 deletions README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SSL_CERT_PATH | TLS を有効にしたいなら、その `cert.pem`
SSL_KEY_PATH | TLS を有効にしたいなら、その `key.pem` へのパス | | -
APP_PORT | このサービスが待機する `ポート番号` | | 80
ACCESS_LOG | 標準出力へアクセスログを送る | | false
STRIP_PATH | 指定した Prefix を S3 のパスから削除 | | -

### 2. アプリを起動します

Expand Down
38 changes: 23 additions & 15 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
machine:
environment:
GO15VENDOREXPERIMENT: 1
REPO_ROOT: "${HOME}/.go_workspace/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}"
CHECKOUT_PATH: ${HOME}/${CIRCLE_PROJECT_REPONAME}
post:
- >
echo "export BUILD_VERSION=\"`git --git-dir=${CHECKOUT_PATH}/.git describe --always --dirty`\"" >> ~/.circlerc;
echo "export BUILD_DATE=\"`date +%FT%T%z`\"" >> ~/.circlerc;
IMPORT_PATH: "github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
PRIVATE_GOPATH: "$(echo $GOPATH | sed 's/:.*$//g')" # Needed because CircleCI has two paths in the GOPATH.
REPO_ROOT: "$PRIVATE_GOPATH/src/$IMPORT_PATH"

dependencies:
cache_directories:
- ~/cache
pre:
- go get -u github.com/tools/godep
- go get -u github.com/golang/lint/golint

checkout:
# Prepare directories.
- mkdir -p ~/cache "$PRIVATE_GOPATH/src/$IMPORT_PATH"
# Install go 1.7
- sudo rm -rf /usr/local/go
- cd ~/cache && if [ ! -e go1.7.5.linux-amd64.tar.gz ]; then wget https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gz; fi
- cd ~/cache && sudo tar -C /usr/local -xzf go1.7.5.linux-amd64.tar.gz
- go version
# Install test utils
- go get github.com/golang/dep
- go get github.com/golang/lint/golint
post:
- mkdir -p ${REPO_ROOT}
- cp -rf ${CHECKOUT_PATH} ${HOME}/.go_workspace/src/github.com/${CIRCLE_PROJECT_USERNAME}/
- >
echo "export BUILD_VERSION=\"`git --git-dir=${CHECKOUT_PATH}/.git describe --always --dirty`\"" >> ~/.circlerc;
echo "export BUILD_DATE=\"`date +%FT%T%z`\"" >> ~/.circlerc;
override:
# Copy repository to GOPATH.
- rsync -azC --delete ./ "$PRIVATE_GOPATH/src/$IMPORT_PATH/"

test:
pre:
- cd ${REPO_ROOT} && godep restore
- cd ${REPO_ROOT} && dep ensure; exit 0
override:
- cd ${REPO_ROOT} && for package in `go list ./...| grep -v vendor`; do golint ${package}; done
- cd ${REPO_ROOT} && test -z "$(gofmt -s -l . | tee /dev/stderr)"
- cd ${REPO_ROOT} && go vet ./...
- cd ${REPO_ROOT} && godep go test -cover -bench -benchmem `go list ./... | grep -v /vendor/` -v
- cd ${REPO_ROOT} && go test -cover -bench -benchmem `go list ./... | grep -v /vendor/` -v

deployment:
release:
Expand Down
30 changes: 0 additions & 30 deletions dev/docker-compose-godep.yml

This file was deleted.

8 changes: 3 additions & 5 deletions dev/docker-compose-gox.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# export BUILD_VERSION=v0.1.0
# export BUILD_DATE=2016-02-15T12:00:00+0900
# docker-compose -f dev/docker-compose-gox.yml run build
# docker-compose -f dev/docker-compose-gox.yml run --rm build

build:
image: pottava/gox:go1.5
command: --osarch "linux/amd64 darwin/amd64 windows/amd64" -ldflags "-X main.version=$BUILD_VERSION -X=main.date $BUILD_DATE" -output "dist/{{.OS}}_{{.Arch}}"
environment:
- GO15VENDOREXPERIMENT=1
image: pottava/gox:go1.8
command: --osarch "linux/amd64 darwin/amd64 windows/amd64" -ldflags "-X main.version=$BUILD_VERSION -X main.date=$BUILD_DATE" -output "dist/{{.OS}}_{{.Arch}}"
volumes:
- $GOPATH/src/github.com/pottava/aws-s3-proxy:/go/src/github.com/pottava/aws-s3-proxy
working_dir: /go/src/github.com/pottava/aws-s3-proxy
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "2"

services:
app:
image: pottava/godep:go1.5
image: pottava/golang:1.8
command: go run /go/src/github.com/pottava/aws-s3-proxy/main.go
ports:
- 8080:80
Expand Down
31 changes: 31 additions & 0 deletions lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"memo": "766fba5c620757431b50b5b1ead972d8080a43237cca2a9edbf9a5f54a5545db",
"projects": [
{
"name": "github.com/aws/aws-sdk-go",
"branch": "master",
"revision": "830984cdef47f8ac0d4883012367bf75e5ccac2c",
"packages": [
"aws",
"aws/session",
"service/s3"
]
},
{
"name": "github.com/go-ini/ini",
"version": "v1.24.0",
"revision": "e3c2d47c61e5333f9aa2974695dd94396eb69c75",
"packages": [
"."
]
},
{
"name": "github.com/jmespath/go-jmespath",
"version": "0.2.2",
"revision": "3433f3ea46d9f8019119e7dd41274e112a2359a9",
"packages": [
"."
]
}
]
}
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ type config struct {
accessLog bool // ACCESS_LOG
sslCert string // SSL_CERT_PATH
sslKey string // SSL_KEY_PATH
stripPath string // STRIP_PATH
}

type Symlink struct {
type symlink struct {
URL string
}

Expand Down Expand Up @@ -98,6 +99,7 @@ func configFromEnvironmentVariables() *config {
accessLog: accessLog,
sslCert: os.Getenv("SSL_CERT_PATH"),
sslKey: os.Getenv("SSL_KEY_PATH"),
stripPath: os.Getenv("STRIP_PATH"),
}
// Proxy
log.Printf("[config] Proxy to %v", conf.s3Bucket)
Expand Down Expand Up @@ -168,21 +170,19 @@ func header(r *http.Request, key string) (string, bool) {
func awss3(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path

stripPath := os.Getenv("STRIP_PATH")
if len(stripPath) > 0 {
path = strings.Replace(path, stripPath, "", 1)
if len(c.stripPath) > 0 {
path = strings.Replace(path, c.stripPath, "", 1)
}

idx := strings.Index(path, "symlink.json")
if idx > -1 {
symlink, err := s3get(c.s3Bucket, c.s3KeyPrefix+path[:idx+12])
result, err := s3get(c.s3Bucket, c.s3KeyPrefix+path[:idx+12])
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var link Symlink
var link symlink
buf := new(bytes.Buffer)
buf.ReadFrom(symlink.Body)
buf.ReadFrom(result.Body)
err = json.Unmarshal(buf.Bytes(), &link)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
7 changes: 7 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"github.com/aws/aws-sdk-go": {
"branch": "master"
}
}
}
5 changes: 1 addition & 4 deletions prod/1.5/Dockerfile → prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Dockerfile

FROM alpine:3.4
MAINTAINER @pottava
FROM alpine:3.5

LABEL com.github.pottava.application="aws-s3-proxy" \
com.github.pottava.usage="docker run -d -p 8080:80 -e AWS_REGION -e AWS_S3_BUCKET -e BASIC_AUTH_USER -e BASIC_AUTH_PASS pottava/s3-proxy" \
Expand Down

0 comments on commit 5c13ead

Please sign in to comment.