Skip to content

Commit c355c3a

Browse files
committed
initial commit of the basic repo structure
1 parent 47b839b commit c355c3a

16 files changed

+345
-0
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git*
2+
examples/**

.github/ISSUE_TEMPLATE/bug_report.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Additional context**
24+
Add any other context about the problem here.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
general:
2+
bestPracticeViolations:
3+
- DKL-LI-0001
4+
- DKL-LI-0002
5+
- CIS-DI-0005
6+
- CIS-DI-0006

.github/workflows/containerscan.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: ContainerScan
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
ContainerScan:
12+
name: ContainerScan
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Set up Go 1.x
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ^1.15
20+
id: go
21+
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v2
24+
25+
- name: Build Image
26+
run: |
27+
docker build . --file Dockerfile --tag scan-image:${{ github.sha }} --build-arg VERSION=${{ github.sha }}
28+
29+
- uses: Azure/container-scan@v0
30+
with:
31+
image-name: scan-image:${{ github.sha }}

.github/workflows/go.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Set up Go 1.x
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ^1.15
20+
id: go
21+
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v2
24+
25+
- name: Build
26+
run: go build -v .
27+
28+
- name: Test
29+
run: go test -v .

.github/workflows/gosec.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Gosec
2+
on: [push, pull_request]
3+
jobs:
4+
gosec:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout Source
8+
uses: actions/checkout@v2
9+
- name: Download Gosec
10+
run: curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sudo sh -s -- -b /usr/bin latest
11+
- name: Run Gosec Security Scanner
12+
#G107: Url provided to HTTP request as taint input
13+
#G109: Potential Integer overflow made by strconv.Atoi result conversion to int16/32
14+
#G304: prevent loading configuration files from variable locations (we want to do this in local development)
15+
#G601: Implicit memory aliasing in for loop. (disabled due to false positives for safe code)
16+
run: gosec -exclude=G107,G109,G304,G601 ./...

.github/workflows/publish.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
# Publish `v*` tags as releases.
6+
tags:
7+
- v*
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Set up Go 1.x
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: ^1.15
18+
id: go
19+
20+
- name: Check out code into the Go module directory
21+
uses: actions/checkout@v2
22+
23+
- name: Build
24+
run: go build -v .
25+
26+
- name: Test
27+
run: go test -v .
28+
publish:
29+
runs-on: ubuntu-latest
30+
if: github.event_name == 'push'
31+
# Ensure test job passes before pushing image.
32+
needs: test
33+
steps:
34+
-
35+
name: Checkout
36+
uses: actions/checkout@v2
37+
-
38+
name: Docker meta
39+
id: docker_meta
40+
uses: crazy-max/ghaction-docker-meta@v1
41+
with:
42+
images: ${{ secrets.DOCKER_HUB_USERNAME }}/k8s-aws-ebs-tagger,ghcr.io/${{ github.repository_owner }}/k8s-aws-ebs-tagger
43+
-
44+
name: Set up QEMU
45+
uses: docker/setup-qemu-action@v1
46+
-
47+
name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v1
49+
-
50+
name: Login to DockerHub
51+
uses: docker/login-action@v1
52+
if: github.event_name != 'pull_request'
53+
with:
54+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
55+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
56+
-
57+
name: Login to GitHub Container Registry
58+
uses: docker/login-action@v1
59+
if: github.event_name != 'pull_request'
60+
with:
61+
registry: ghcr.io
62+
username: ${{ github.repository_owner }}
63+
password: ${{ secrets.GHCR_PAT }}
64+
-
65+
name: Build and push
66+
id: docker_build
67+
uses: docker/build-push-action@v2
68+
with:
69+
context: .
70+
file: ./Dockerfile
71+
build-args: VERSION=${{ steps.docker_meta.outputs.version }}
72+
platforms: linux/amd64,linux/arm64
73+
push: ${{ github.event_name != 'pull_request' }}
74+
tags: ${{ steps.docker_meta.outputs.tags }}
75+
labels: ${{ steps.docker_meta.outputs.labels }}

CODE_OF_CONDUCT.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This project follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Contributions are welcome so long as they follow the [CODE OF CONDUCT](CODE_OF_CONDUCT.md)

Dockerfile

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM golang:1.15-alpine AS builder
2+
3+
ARG VERSION=0.0.1
4+
ENV APP_NAME=k8s-aws-ebs-tagger
5+
ENV APP_VERSION=$VERSION
6+
ARG TARGETARCH
7+
8+
ENV GO111MODULE=on \
9+
CGO_ENABLED=0 \
10+
GOOS=linux \
11+
GOARCH=$TARGETARCH
12+
13+
# Move to working directory /build
14+
WORKDIR /build
15+
16+
# Copy and download dependency using go mod
17+
COPY go.mod go.sum ./
18+
RUN go mod download
19+
20+
# Copy the code into the container
21+
COPY . .
22+
23+
# Build the application
24+
RUN date +%s > buildtime
25+
RUN APP_BUILD_TIME=$(cat buildtime); \
26+
go build -ldflags="-X 'main.buildTime=${APP_BUILD_TIME}' -X 'main.buildVersion=${APP_VERSION}'" -o ${APP_NAME} .
27+
28+
# Move to /dist directory as the place for resulting binary folder
29+
WORKDIR /app
30+
31+
# Copy binary from build to main folder
32+
RUN cp /build/${APP_NAME} .
33+
34+
RUN addgroup -S k8s-aws-ebs-tagger && adduser -S k8s-aws-ebs-tagger -G k8s-aws-ebs-tagger
35+
36+
# Build a small image
37+
FROM scratch
38+
COPY --from=builder /etc/passwd /etc/passwd
39+
USER k8s-aws-ebs-tagger
40+
# https://github.com/aws/aws-sdk-go/issues/2322
41+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
42+
COPY --from=builder /app/${APP_NAME} /
43+
44+
CMD ["/k8s-aws-ebs-tagger"]

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# k8s-aws-ebs-tagger
22
A utility to tag AWS EBS volumes based on the PV labels / annotations
3+
4+
![Go](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/Go/badge.svg) ![Gosec](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/Gosec/badge.svg) ![ContainerScan](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/ContainerScan/badge.svg) [![GitHub tag](https://img.shields.io/github/tag/mtougeron/k8s-aws-ebs-tagger.svg)](https://github.com/mtougeron/k8s-aws-ebs-tagger/tags/)
5+
6+
The `k8s-aws-ebs-tagger` watches for new PersistentVolumes and when new AWS EBS volumes are created it adds tags based on the PV labels to the created EBS volume.
7+
8+
#### Container Image
9+
10+
Images are available on the [GitHub Container Registry](https://github.com/users/mtougeron/packages/container/k8s-aws-ebs-tagger/versions) and [DockerHub](https://hub.docker.com/repository/docker/mtougeron/k8s-aws-ebs-tagger)
11+
12+
### Licensing
13+
14+
This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.

SECURITY.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported | gosec |
6+
| ------- | ------------------ | ------ |
7+
| latest | :white_check_mark: | ![Gosec](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/Gosec/badge.svg) |
8+
9+
## Scanning
10+
11+
Security scanning uses [gosec](https://github.com/securego/gosec) via a [GitHub workflow](https://github.com/mtougeron/k8s-aws-ebs-tagger/actions?query=workflow%3AGosec)
12+
13+
## Reporting a Vulnerability
14+
15+
To report a security issue, please contact [email protected]

go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/mtougeron/k8s-aws-ebs-tagger
2+
3+
go 1.15
4+
5+
require (
6+
github.com/sirupsen/logrus v1.7.0
7+
)

go.sum

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3+
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
4+
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
5+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
6+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
7+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

main.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Licensed to Michael Tougeron <[email protected]> under
2+
// one or more contributor license agreements. See the LICENSE
3+
// file distributed with this work for additional information
4+
// regarding copyright ownership.
5+
// Michael Tougeron <[email protected]> licenses this file
6+
// to you under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
19+
package main
20+
21+
import (
22+
"os"
23+
"strconv"
24+
25+
log "github.com/sirupsen/logrus"
26+
)
27+
28+
var (
29+
buildVersion string = ""
30+
buildTime string = ""
31+
debugEnv string = os.Getenv("DEBUG")
32+
debug bool
33+
)
34+
35+
func init() {
36+
var err error
37+
if len(debugEnv) != 0 {
38+
debug, err = strconv.ParseBool(debugEnv)
39+
if err != nil {
40+
log.Fatalln("Failed to parse DEBUG Environment variable:", err.Error())
41+
}
42+
}
43+
44+
if debug {
45+
log.SetLevel(log.DebugLevel)
46+
}
47+
48+
// APP Build information
49+
log.Debugln("Application Version:", buildVersion)
50+
log.Debugln("Application Build Time:", buildTime)
51+
}
52+
53+
func main() {
54+
log.Infoln("Application started")
55+
}

0 commit comments

Comments
 (0)