From d3fcfb685146e79a76e187cdcd565f9b280a73e8 Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Fri, 15 Jan 2021 14:36:01 +0100 Subject: [PATCH] Clean up Dockerfile --- .golangci.yml | 1 + Dockerfile | 24 +++++++------ LICENSE | 2 +- go.mod | 5 +-- go.sum | 10 +++--- internal/app/s3manager/mocks/s3.go | 58 +++++++++++++++--------------- 6 files changed, 53 insertions(+), 47 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9222f24..ab5bbb2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,6 +3,7 @@ linters: disable: - exhaustivestruct - funlen + - ifshort - lll - nlreturn - wsl diff --git a/Dockerfile b/Dockerfile index 5a80690..696405a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,17 @@ -FROM golang:1 AS builder -RUN groupadd -r app && useradd --no-log-init -r -g app app -WORKDIR /app +FROM docker.io/library/golang:1 AS builder +WORKDIR /usr/src/app COPY . ./ RUN CGO_ENABLED=0 go build -ldflags="-s -w" -a -installsuffix cgo -o bin/s3manager ./cmd/s3manager -FROM alpine -WORKDIR /app -COPY --from=builder /app/bin/s3manager ./ -COPY --from=builder /app/web ./web/ -COPY --from=builder /etc/passwd /etc/passwd -RUN apk update && apk add --no-cache ca-certificates -USER app +FROM docker.io/library/alpine:latest +WORKDIR /usr/src/app +RUN addgroup -S s3manager && adduser -S s3manager -G s3manager +RUN apk add --no-cache \ + ca-certificates \ + dumb-init +COPY --from=builder --chown=s3manager:s3manager /usr/src/app/bin/s3manager ./ +COPY --from=builder --chown=s3manager:s3manager /usr/src/app/web ./web/ +USER s3manager EXPOSE 8080 -ENTRYPOINT ["./s3manager"] +ENTRYPOINT [ "/usr/bin/dumb-init", "--" ] +CMD [ "/usr/src/app/s3manager" ] diff --git a/LICENSE b/LICENSE index dfbdbd9..4bac77f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2016 Tobias Fuhrimann +Copyright 2016 Lena Fuhrimann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/go.mod b/go.mod index c483980..111f6a3 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/go-ini/ini v1.62.0 // indirect - github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect + github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe // indirect github.com/mastertinner/adapters v0.0.0-20201230105432-b946812c1f03 github.com/matryer/is v1.4.0 github.com/matryer/way v0.0.0-20180416093233-9632d0c407b0 @@ -13,7 +13,8 @@ require ( github.com/smartystreets/assertions v1.2.0 // indirect github.com/smartystreets/goconvey v1.6.4 // indirect golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect - golang.org/x/sys v0.0.0-20210112080510-489259a85091 // indirect + golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect + golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect golang.org/x/text v0.3.5 // indirect gopkg.in/ini.v1 v1.62.0 // indirect ) diff --git a/go.sum b/go.sum index 387ddbf..75f99af 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0= -github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe h1:rcf1P0fm+1l0EjG16p06mYLj9gW9X36KgdHJ/88hS4g= +github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -207,6 +207,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -248,8 +250,8 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/app/s3manager/mocks/s3.go b/internal/app/s3manager/mocks/s3.go index 72cade2..f6f692d 100644 --- a/internal/app/s3manager/mocks/s3.go +++ b/internal/app/s3manager/mocks/s3.go @@ -5,7 +5,7 @@ package mocks import ( "github.com/mastertinner/s3manager/internal/app/s3manager" - "github.com/minio/minio-go" + minio "github.com/minio/minio-go" "io" "sync" ) @@ -16,37 +16,37 @@ var _ s3manager.S3 = &S3Mock{} // S3Mock is a mock implementation of s3manager.S3. // -// func TestSomethingThatUsesS3(t *testing.T) { +// func TestSomethingThatUsesS3(t *testing.T) { // -// // make and configure a mocked s3manager.S3 -// mockedS3 := &S3Mock{ -// GetObjectFunc: func(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) { -// panic("mock out the GetObject method") -// }, -// ListBucketsFunc: func() ([]minio.BucketInfo, error) { -// panic("mock out the ListBuckets method") -// }, -// ListObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { -// panic("mock out the ListObjectsV2 method") -// }, -// MakeBucketFunc: func(bucketName string, location string) error { -// panic("mock out the MakeBucket method") -// }, -// PutObjectFunc: func(bucketName string, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions) (int64, error) { -// panic("mock out the PutObject method") -// }, -// RemoveBucketFunc: func(bucketName string) error { -// panic("mock out the RemoveBucket method") -// }, -// RemoveObjectFunc: func(bucketName string, objectName string) error { -// panic("mock out the RemoveObject method") -// }, -// } +// // make and configure a mocked s3manager.S3 +// mockedS3 := &S3Mock{ +// GetObjectFunc: func(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) { +// panic("mock out the GetObject method") +// }, +// ListBucketsFunc: func() ([]minio.BucketInfo, error) { +// panic("mock out the ListBuckets method") +// }, +// ListObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { +// panic("mock out the ListObjectsV2 method") +// }, +// MakeBucketFunc: func(bucketName string, location string) error { +// panic("mock out the MakeBucket method") +// }, +// PutObjectFunc: func(bucketName string, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions) (int64, error) { +// panic("mock out the PutObject method") +// }, +// RemoveBucketFunc: func(bucketName string) error { +// panic("mock out the RemoveBucket method") +// }, +// RemoveObjectFunc: func(bucketName string, objectName string) error { +// panic("mock out the RemoveObject method") +// }, +// } // -// // use mockedS3 in code that requires s3manager.S3 -// // and then make assertions. +// // use mockedS3 in code that requires s3manager.S3 +// // and then make assertions. // -// } +// } type S3Mock struct { // GetObjectFunc mocks the GetObject method. GetObjectFunc func(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error)