From b32dd54cc21e9ebdc874b2c7b5b4897c074c5e52 Mon Sep 17 00:00:00 2001 From: Jiri Mikaus Date: Wed, 15 Nov 2023 11:52:51 +0100 Subject: [PATCH] add gh actions --- .github/workflows/docker-build.yml | 28 +++++++++ .github/workflows/test.yml | 51 +++++++++++++++ Dockerfile | 91 +++++++++++++++++---------- Dockerfile-bak | 34 ++++++++++ app/version.go | 5 ++ certs/crl/certs/intermediate.crl.der | Bin 0 -> 829 bytes docker-compose.yml | 2 +- server.go | 5 +- server_test.go | 2 +- 9 files changed, 179 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/docker-build.yml create mode 100644 .github/workflows/test.yml create mode 100644 Dockerfile-bak create mode 100644 app/version.go create mode 100644 certs/crl/certs/intermediate.crl.der diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..fac1d91 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,28 @@ +name: Build docker image and push to Harbor +on: + push: + tags: + - '*' + +jobs: + Built-login-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build and push image + run: |- + GIT_COMMIT=$(git rev-parse HEAD) + VERSION_TAG=$(git describe --exact-match --tags 2>/dev/null) + VERSION_TAG=$(echo $VERSION_TAG | tr '[A-Z]' '[a-z]') + IMAGE_TAG="harbor.whalebone.io/whalebone/${{ github.event.repository.name }}:${VERSION_TAG}" + IMAGE_TAG=$(echo $IMAGE_TAG | tr '[A-Z]' '[a-z]') + + echo "${{ secrets.DOCKER_PASSWORD }}" | docker login harbor.whalebone.io/whalebone -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + + docker build . --file Dockerfile --tag "${IMAGE_TAG}" \ + --build-arg VERSION="${VERSION_TAG}" \ + --build-arg GIT_COMMIT="${GIT_COMMIT}" \ + --build-arg GH_USERNAME=${{ secrets.GH_USERNAME }} \ + --build-arg GH_TOKEN=${{ secrets.GH_TOKEN }} + + docker push "${IMAGE_TAG}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..bb088cc --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: Test + +on: + push: + branches: + - "**" + +jobs: + test: + runs-on: ubuntu-latest + services: + minio: + image: bitnami/minio:latest + env: + MINIO_ROOT_USER: minio + MINIO_ROOT_PASSWORD: minio123 + ports: + - 9000:9000 + steps: + - uses: actions/checkout@v4 + - name: Set up go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + # - name: Setup Go and Git for private modules + # run: | + # go env -w GOPRIVATE=github.com/whalebone/* + # git config --global url."https://${{ secrets.GH_USERNAME }}:${{ secrets.GH_TOKEN }}@github.com".insteadOf "https://github.com" + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + skip-pkg-cache: true + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + skip-build-cache: true + + - name: Test Go packages + run: | + go test -v -covermode=atomic -coverpkg=./... -coverprofile coverage.out ./... -p=1 count=1 -cpu 2 + go tool cover -func=coverage.out diff --git a/Dockerfile b/Dockerfile index d5675aa..d18d5a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,57 @@ -# Multi-stage build: The final stage adds just 9 MB of our Go binary on the top of the base image, e.g.: -# fedora 29 24508ec0e667 260MB -# karm/serve-file 1.0.0 3cebf268c53e 269MB - -# build stage -############# -# Why 25 and not 29? newer Curl/NSS on Fedora 27+ fails to handshake with the test -# certificates on the grounds of "unsupported purpose"; TODO: revisit cert extensions -FROM fedora:25 AS build-env -LABEL Author="Michal Karm Babacek eWHjJq=z(1!tIQ%{Al4uv{aN*v^wrhwSCVE?T>T_3Vqw>*=gQZz&hZ@m>S41sXvy9sM<=K~T&ZTN zA#lnkV5RES7sfj>?{d!2P3mY+Hp;JCsj)F(JKvpLlZCYsmRgGfrak8FnSLnXva5vj z_qvx$a?bFno&CM3*LH@Yl8*kWwg={sU7}X8o?@CFn^Q^}rM7ZC`DZO=yW`fC>sm)% zy9L;vTd>^IIyINeu(ayS2KlDt6Yss%@6q9`+Vr7&S$x=0W~QB9C;j)oU)ixQy3s7BW*UEt5Z}}i87!@pt&kyXclUA&|1Hi(?oFSs z%(zos*32Q0x&7$F<6rvIDWSZv$**8iiY`BU8w5w-Wvd%O{u_(r^R;^rP% zEzgKsJpX4j6|jpb9B0wAiL_^$cVX`7BUfLQitFCs48E|J@nXdPV+$kB&7Y?ImnFM` zB{OL{E3fmFv$wl{Xgn4=HO;oj{cuNS_PoG~hl!K+Hg+A1Tec(3Xd;7jP3N<}vR86S z;#dDNVE&ZbIMwI#m8I8i*$Pa#Uuk;Xk{@ z^`40?kE1Wn*#VZZL#vx5C0O5E~7`%>4WX3q2ODzth$rLH(Q YYt2-L6ISZa&0}BB+;w$DaoN8Y00a_7AOHXW literal 0 HcmV?d00001 diff --git a/docker-compose.yml b/docker-compose.yml index a700dbf..c32e1d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: ports: - "9000:9000" - "9001:9001" - command: server --console-address :9001 /data --certs-dir /minio-conf/certs + command: server --console-address :9001 /data environment: MINIO_ROOT_USER: minio MINIO_ROOT_PASSWORD: minio123 diff --git a/server.go b/server.go index 8c6469d..e32be6c 100644 --- a/server.go +++ b/server.go @@ -32,12 +32,11 @@ import ( "time" minio "github.com/minio/minio-go" + "whalebone.io/serve-file/app" "whalebone.io/serve-file/config" "whalebone.io/serve-file/validation" ) -const version = "1.0.0" - //nolint:gocognit,cyclop func createServer(settings *config.Settings) *http.Server { mux := http.NewServeMux() @@ -283,7 +282,7 @@ func main() { } done <- true }(srv) - log.Printf("Running version %s. Ctrl+C to stop.", version) + log.Printf("Running version %s (%s). Ctrl+C to stop.", app.Version, app.GitCommit) <-done log.Printf("Stopped.") } diff --git a/server_test.go b/server_test.go index 8d3abfb..051e1c2 100644 --- a/server_test.go +++ b/server_test.go @@ -50,7 +50,7 @@ var ( caCertBase64 = testutil.GetBase64(caCertFile) serverCertBase64 = testutil.GetBase64("certs/server/certs/server.cert.pem") serverKeyBase64 = testutil.GetBase64("certs/server/private/server.key.nopass.pem") - crlBase64 = testutil.GetBase64("certs/crl/certs/intermediate.crl.pem") + crlBase64 = testutil.GetBase64("certs/crl/certs/intermediate.crl.der") testMutex = &sync.Mutex{} )