Skip to content

Commit

Permalink
Merge pull request #8 from mwennrich/ghcr
Browse files Browse the repository at this point in the history
build ghcr image
  • Loading branch information
mwennrich authored Mar 30, 2023
2 parents ea755ce + 934151e commit c427ca3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ghcr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: Docker Build Action
on:
pull_request:
branches:
- main
release:
types:
- published
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
name: Docker Build
runs-on: ubuntu-latest

steps:
- name: Log in to the container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
args: -p bugs -p unused --timeout=3m

- name: Make tag
run: |
[ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true
- name: Build and push image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }}
5 changes: 2 additions & 3 deletions .github/workflows/latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ jobs:
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.1
go-version: '1.20.x'

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
args: --timeout=3m -p bugs -p unused

- name: Build the Docker images
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ jobs:
if: steps.fork.outputs.is_fork_pr == 'false'

- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.1
go-version: '1.20.x'

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
args: --timeout=3m -p bugs -p unused

- name: Build
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ jobs:
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.1
go-version: '1.20.x'

- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.51.1
args: --timeout=3m -p bugs -p unused

- name: Build the Docker images
Expand Down
8 changes: 5 additions & 3 deletions alertlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ func parse(payload []byte) (*alertGroup, error) {
return &d, nil
}

// print itearates over the alertgroup and prints all alerts in json format
// printJson prints all alerts in json format
func printJson(ag *alertGroup, m *sync.Mutex) {

m.Lock()
for _, alert := range ag.Alerts {
out := map[string]string{"status": alert.Status}
Expand All @@ -76,7 +75,7 @@ func printJson(ag *alertGroup, m *sync.Mutex) {
m.Unlock()
}

// print iterates over the alertgroup and prints all alerts as key value pairs
// printKV iterates over the alertgroup and prints all alerts as key value pairs
func printKV(ag *alertGroup, m *sync.Mutex) {
m.Lock()
for _, alert := range ag.Alerts {
Expand Down Expand Up @@ -104,14 +103,17 @@ func main() {

http.HandleFunc("/",func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()

b, err := io.ReadAll(r.Body)
if err != nil {
panic(err)
}

ag, err := parse(b)
if err != nil {
panic(err)
}

if jsonOutput {
printJson(ag, &m)
} else {
Expand Down
2 changes: 1 addition & 1 deletion samples/alertloggerStatefulSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
spec:
containers:
- name: alertlogger
image: docker.io/mwennrich/alertlogger:latest
image: ghcr.io/mwennrich/alertlogger:latest
env:
- name: JSON_OUTPUT
value: "true"
Expand Down

0 comments on commit c427ca3

Please sign in to comment.