Skip to content

Commit

Permalink
Merge pull request #6 from shanduur/chore/major-cleanup
Browse files Browse the repository at this point in the history
chore: major cleanup
  • Loading branch information
jecluis authored May 11, 2024
2 parents 2b5252a + ec9442f commit 132c710
Show file tree
Hide file tree
Showing 18 changed files with 698 additions and 620 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Binaries for programs and plugins
bin/
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories
vendor/

# Go workspace file
go.work

# MacOS attributes files
.DS_Store

# Editor configurations
.idea/
.vscode/
16 changes: 13 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Editor configuration, see https://editorconfig.org
; https://editorconfig.org/

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
indent_size = 4
indent_style = tab

[*.md]
max_line_length = off
indent_size = 4
trim_trailing_whitespace = false

eclint_indent_style = unset

[Dockerfile]
indent_size = 4
30 changes: 25 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
*.tmp
# Binaries for programs and plugins
bin/
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories
vendor/

# Go workspace file
go.work

# MacOS attributes files
.DS_Store
.build
*.swp
bin
.idea

# Editor configurations
.idea/
.vscode/
11 changes: 8 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-yaml
Expand All @@ -16,11 +16,16 @@ repos:
- id: check-case-conflict

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.6
hooks:
- id: codespell

- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.4.0
rev: v0.13.0
hooks:
- id: markdownlint-cli2

- repo: https://github.com/golangci/golangci-lint
rev: v1.58.1
hooks:
- id: golangci-lint
78 changes: 68 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,74 @@
FROM gcr.io/distroless/static:latest
LABEL Name="s3gw-cosi-driver"
LABEL maintainers="s3gw maintainers"
LABEL description="s3gw COSI driver"
#########################################################################################
# Build
#########################################################################################

# First stage: building the driver executable.
FROM docker.io/library/golang:1.22.3 as builder

# Set the working directory.
WORKDIR /work

# Prepare dir so it can be copied over to runtime layer.
RUN mkdir -p /var/lib/cosi

# Copy the Go Modules manifests.
COPY go.mod go.mod
COPY go.sum go.sum

# Cache dep before building and copying source so that we don't need to re-download as
# much and so that source changes don't invalidate our downloaded layer.
RUN go mod download

# Copy the go source.
COPY Makefile Makefile
COPY cmd/ cmd/
COPY pkg/ pkg/

# Build.
RUN make build

#########################################################################################
# Runtime
#########################################################################################

# Second stage: building final environment for running the executable.
FROM gcr.io/distroless/static:latest AS runtime

# Copy the executable.
COPY --from=builder --chown=65532:65532 /work/bin/s3gw-cosi-driver /usr/bin/s3gw-cosi-driver

# Copy the volume directory with correct permissions, so driver can bind a socket there.
COPY --from=builder --chown=65532:65532 /var/lib/cosi /var/lib/cosi

# Set volume mount point for app socket.
VOLUME [ "/var/lib/cosi" ]

# Set the final UID:GID to non-root user.
USER 65532:65532

# Disable healthcheck.
HEALTHCHECK NONE

# Few Args for dynamically setting labels.
ARG QUAY_EXPIRATION=Never
ARG S3GW_VERSION=Development
ARG ID=s3gw-cosi-driver

ENV ID=${ID}
# Add labels.

## Standard opencontainers labels.
LABEL org.opencontainers.image.title="s3gw-cosi-driver"
LABEL org.opencontainers.image.description="COSI Driver for s3gw"
LABEL org.opencontainers.image.authors="s3gw maintainers"
LABEL org.opencontainers.image.vendor="s3gw-tech"
LABEL org.opencontainers.image.version="${S3GW_VERSION}"
LABEL org.opencontainers.image.license="Apache-2.0"
LABEL org.opencontainers.image.source="https://github.com/s3gw-tech/s3gw-cosi-driver"
LABEL org.opencontainers.image.documentation="http://docs.s3gw.tech"
LABEL org.opencontainers.image.base.name="gcr.io/distroless/static:latest"

LABEL Version=${S3GW_VERSION}
LABEL quay.expires-after=${QUAY_EXPIRATION}
## Quay specific labels.
LABEL quay.expires-after="${QUAY_EXPIRATION}"

COPY ./bin/s3gw-cosi-driver s3gw-cosi-driver
ENTRYPOINT ["/s3gw-cosi-driver"]
# Set the entrypoint.
ENTRYPOINT [ "/usr/bin/s3gw-cosi-driver" ]
CMD []
41 changes: 31 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2023 SUSE, LLC.
# Copyright 2024 s3gw contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,26 +17,46 @@ REGISTRY_NAME ?= quay.io/s3gw
IMAGE_NAME ?= s3gw-cosi-driver
IMAGE_TAG ?= latest

all: build container push
GO ?= go
ENGINE ?= docker

.PHONY: build container clean
GOFLAGS ?= -trimpath
LDFLAGS ?= -s -w -extldflags "-static"
GO_SETTINGS += CGO_ENABLED=0

ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
.PHONY: all
all: build container push

.PHONY: build
build:
mkdir -p bin
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o ./bin/s3gw-cosi-driver ./cmd/*
$(GO_SETTINGS) $(GO) build \
$(GOFLAGS) \
-ldflags="$(LDFLAGS)" \
-o=./bin/s3gw-cosi-driver \
./cmd/s3gw-cosi-driver

.PHONY: test
test:
mkdir -p bin
CGO_ENABLED=0 GOOS=linux go test ./cmd/*
$(GO_SETTINGS) $(GO) test $(GOFLAGS) \
-race \
-cover -covermode=atomic -coverprofile=coverage.out \
./...

.PHONY: container
container:
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile .
docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG)
$(ENGINE) build \
--tag=$(IMAGE_NAME):$(IMAGE_TAG) \
--file=Dockerfile \
.

.PHONY: push
push:
docker push $(REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG)
$(ENGINE) tag \
$(IMAGE_NAME):$(IMAGE_TAG)
$(REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG)
$(ENGINE) push \
$(REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_TAG)

.PHONY: clean
clean:
-rm -rf bin
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# s3gw-cosi-driver

COSI driver implementation for [s3gw](https://github.com/aquarist-labs/s3gw).
COSI driver implementation for [s3gw](https://github.com/s3gw-tech/s3gw).

Note that the COSI driver alone is not sufficient to get COSI working
on a Kubernetes cluster.
Expand All @@ -19,15 +19,13 @@ make build
Now build the docker image and provide a tag as `quay.io/s3gw/s3gw-cosi-driver:latest`

```shell
$ make container
Sending build context to Docker daemon 41.95MB
make container
```

You can tag and push the docker image to a registry with:

```shell
docker tag s3gw-cosi-driver:latest quay.io/s3gw/s3gw-cosi-driver:latest
docker push quay.io/s3gw/s3gw-cosi-driver:latest
make push REGISTRY_NAME=quay.io/s3gw
```

## Examples
Expand Down
Loading

0 comments on commit 132c710

Please sign in to comment.