Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 746ad15

Browse files
authored
Merge pull request #1 from mariadb-operator/init
Initial version of MariaDB init container.
2 parents 4157144 + cb13a7e commit 746ad15

File tree

26 files changed

+2176
-2
lines changed

26 files changed

+2176
-2
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug
3+
about: Create a bug report to help us improve
4+
title: "[Bug] "
5+
labels: bug
6+
assignees: mmontes11
7+
8+
---
9+
10+
<!--
11+
Bugs should be filed for issues encountered whilst operating mariadb-operator/init.
12+
Please provide as much detail as possible.
13+
-->
14+
15+
**Describe the bug**
16+
<!--
17+
A clear and concise description of what the bug is.
18+
Tip: you can use
19+
```
20+
<code here>
21+
```
22+
for code blocks of your kubectl output or YAML files.
23+
-->
24+
25+
**Expected behaviour**
26+
<!--A concise description of what you expected to happen.-->
27+
28+
**Steps to reproduce the bug**
29+
<!--Steps to reproduce the bug should be clear and easily reproducible to help people
30+
gain an understanding of the problem.-->
31+
32+
**Additional context**
33+
<!--Add any other context here.-->
34+
35+
**Environment details**:
36+
- Kubernetes version:
37+
- mariadb-operator version:
38+
- init version:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: "[Feature]"
5+
labels: feature
6+
assignees: mmontes11
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-->
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 here.-->
21+
22+
**Environment details**:
23+
- Kubernetes version:
24+
- mariadb-operator version:
25+
- init version:

.github/workflows/ci.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: {}
8+
9+
env:
10+
GOLANGCI_VERSION: "v1.52.2"
11+
12+
jobs:
13+
detect-noop:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
noop: ${{ steps.noop.outputs.should_skip }}
17+
steps:
18+
- name: Detect no-op changes
19+
id: noop
20+
uses: fkirc/[email protected]
21+
with:
22+
github_token: ${{ secrets.GITHUB_TOKEN }}
23+
paths_ignore: '["**.md"]'
24+
concurrent_skipping: false
25+
26+
lint:
27+
name: Lint
28+
runs-on: ubuntu-latest
29+
needs: detect-noop
30+
if: ${{ needs.detect-noop.outputs.noop != 'true' }}
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v3
34+
35+
- name: Setup Go
36+
uses: actions/setup-go@v3
37+
with:
38+
go-version-file: "go.mod"
39+
cache: true
40+
41+
- name: GolangCI Lint
42+
uses: golangci/golangci-lint-action@v3
43+
with:
44+
version: ${{ env.GOLANGCI_VERSION }}
45+
46+
build:
47+
name: Build
48+
runs-on: ubuntu-latest
49+
needs: detect-noop
50+
if: ${{ needs.detect-noop.outputs.noop != 'true' }}
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v2
54+
55+
- name: Setup Go
56+
uses: actions/setup-go@v3
57+
with:
58+
go-version-file: "go.mod"
59+
cache: true
60+
61+
- name: Build
62+
run: make build
63+
64+
- name: Build Docker
65+
run: make docker-build
66+
env:
67+
PLATFORM: linux/amd64
68+
69+
test:
70+
name: Test
71+
runs-on: ubuntu-latest
72+
needs: detect-noop
73+
if: ${{ needs.detect-noop.outputs.noop != 'true' }}
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v2
77+
78+
- name: Setup Go
79+
uses: actions/setup-go@v3
80+
with:
81+
go-version-file: "go.mod"
82+
cache: true
83+
84+
- name: Test
85+
run: make test

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
GORELEASER_VERSION: "v1.18.2"
10+
11+
jobs:
12+
release:
13+
name: Release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Fetch tags
22+
run: git fetch --force --tags
23+
24+
- name: Setup QEMU
25+
uses: docker/setup-qemu-action@v2
26+
27+
- name: Setup Docker Buildx
28+
uses: docker/setup-buildx-action@v2
29+
id: buildx
30+
31+
- name: Login to container Registry
32+
uses: docker/login-action@v2
33+
with:
34+
username: ${{ github.repository_owner }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
registry: ghcr.io
37+
38+
- name: Prepare
39+
id: prep
40+
run: |
41+
VERSION=sha-${GITHUB_SHA::8}
42+
if [[ $GITHUB_REF == refs/tags/* ]]; then
43+
VERSION=${GITHUB_REF/refs\/tags\//}
44+
fi
45+
echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
46+
echo ::set-output name=VERSION::${VERSION}
47+
48+
- name: Publish multi-arch Docker image
49+
uses: docker/build-push-action@v2
50+
with:
51+
push: true
52+
builder: ${{ steps.buildx.outputs.name }}
53+
context: .
54+
file: ./Dockerfile
55+
platforms: linux/arm64,linux/amd64
56+
tags: |
57+
ghcr.io/${{ github.repository_owner }}/init:${{ steps.prep.outputs.VERSION }}
58+
ghcr.io/${{ github.repository_owner }}/init:latest
59+
labels: |
60+
org.opencontainers.image.title=${{ github.event.repository.name }}
61+
org.opencontainers.image.description=${{ github.event.repository.description }}
62+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
63+
org.opencontainers.image.url=${{ github.event.repository.html_url }}
64+
org.opencontainers.image.revision=${{ github.sha }}
65+
org.opencontainers.image.version=${{ steps.prep.outputs.VERSION }}
66+
org.opencontainers.image.created=${{ steps.prep.outputs.BUILD_DATE }}
67+
68+
- name: Set GORELEASER_PREVIOUS_TAG
69+
run: echo "GORELEASER_PREVIOUS_TAG=$(git tag -l "v*" --sort=-version:refname | head -n 2 | tail -n 1)" >> $GITHUB_ENV
70+
71+
- name: GoReleaser
72+
uses: goreleaser/goreleaser-action@v4
73+
with:
74+
version: ${{ env.GORELEASER_VERSION }}
75+
args: release
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
*.html
14+
15+
# Dependency directories (remove the comment below to include it)
16+
vendor/
17+
18+
# Binaries
19+
bin/
20+
21+
# Packaged Helm charts
22+
*.tgz
23+
24+
# Directory to keep MariaDB files used for development
25+
mariadb/

.golangci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
linters-settings:
2+
gocyclo:
3+
min-complexity: 20
4+
lll:
5+
line-length: 140
6+
misspell:
7+
locale: US
8+
9+
linters:
10+
disable-all: true
11+
enable:
12+
- unused
13+
- errcheck
14+
- gocyclo
15+
- gofmt
16+
- goimports
17+
- gosimple
18+
- govet
19+
- ineffassign
20+
- lll
21+
- misspell
22+
- nestif
23+
- staticcheck
24+
- typecheck
25+
- unused
26+
- bodyclose
27+
- noctx
28+
29+
run:
30+
timeout: 5m
31+
go: "1.20"

.goreleaser.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
changelog:
2+
use: github-native
3+
builds:
4+
- id: init
5+
main: main.go
6+
binary: "init_{{ .Version }}_{{ .Arch }}"
7+
env:
8+
- CGO_ENABLED=0
9+
goos:
10+
- linux
11+
- darwin
12+
goarch:
13+
- amd64
14+
- arm64

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Package",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "main.go"
13+
}
14+
]
15+
}

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM golang:1.20.4-alpine3.18 AS builder
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
ENV CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH}
6+
7+
WORKDIR /app
8+
9+
COPY go.mod go.sum /app/
10+
RUN go mod download
11+
12+
COPY . /app
13+
RUN go build -o init main.go
14+
15+
FROM gcr.io/distroless/static AS app
16+
17+
WORKDIR /
18+
COPY --from=builder /app/init /bin/init
19+
USER 65532:65532
20+
21+
ENTRYPOINT ["/bin/init"]

0 commit comments

Comments
 (0)