From 7dc383a05e820ae273b3e6b40e8058f0c15fa4dd Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 13:20:42 +0100 Subject: [PATCH 01/12] init dockerfile --- Dockerfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b71fae2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.19 AS build-stage + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY *.go ./ +RUN CGO_ENABLED=0 GOOS=linux go build -o /downdetector-exporter + +FROM gcr.io/distroless/base-debian12 AS build-release-stage + +WORKDIR / +COPY --from=build-stage /downdetector-exporter /downdetector-exporter +EXPOSE 9313 +USER nonroot:nonroot +ENTRYPOINT ["/downdetector-exporter"] + From 478a0ebd6098250d2384421066a4af7cb72595ff Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:16:20 +0100 Subject: [PATCH 02/12] add Docker usage examples --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/README.md b/README.md index 0c08fca..1427809 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,59 @@ METRICS_PATH LOG_LEVEL ``` +#### Running in Docker Compose + +Example of running in docker compose using some the above variables + +``` +services: + downdetector-exporter: + container_name: downdetector-exporter + image: ghcr.io/kic68/downdetector-exporter + restart: always + environment: + - COMPANY_IDS=23456,12345,34567 + - DD_USERNAME=client-id + - DD_PASSWORD=secret-token +``` + +#### Running in Kubernetes + +Example of running in kubernetes: + +``` +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: downdetector-exporter + name: downdetector-exporter +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: downdetector-exporter + strategy: {} + template: + metadata: + labels: + io.kompose.service: downdetector-exporter + spec: + containers: + - env: + - name: COMPANY_IDS + value: "23456,12345,34567" + - name: DD_USERNAME + value: client-id + - name: DD_PASSWORD + value: secret-token + image: ghcr.io/kic68/downdetector-exporter + name: downdetector-exporter + resources: {} + restartPolicy: Always +status: {} +``` + ### Grafana dashboard There's a grafana_dashboard.json file in the repository which can be imported to Grafana. From 7539c7968695240827eb656785197ae3def2cefa Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:18:18 +0100 Subject: [PATCH 03/12] build docker image via github actions --- .github/workflows/ci.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..500cc13 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,23 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + +jobs: + docker-build-push: + runs-on: ubuntu-latest + steps: + - name: 'Pull Code' + uses: actions/checkout@main + - name: 'Login to GitHub Container Registry' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{github.actor}} + password: ${{secrets.GITHUB_TOKEN}} + - name: 'Build Inventory Image' + run: | + docker build . --tag ghcr.io/nohn/downdetector-exporter:latest + docker push ghcr.io/nohn/downdetector-exporter:latest From 5914e80a53be52c9adb18cba303c54ca8c0e0c0e Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:19:21 +0100 Subject: [PATCH 04/12] build docker image via github actions --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 500cc13..789cf6a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ master ] + branches: [ master, dockerfile ] pull_request: jobs: From 9574930bfdaacd0594ffe65508c79788cf29bec5 Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:21:49 +0100 Subject: [PATCH 05/12] update to docker login action v3 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 789cf6a..876b9ea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: - name: 'Pull Code' uses: actions/checkout@main - name: 'Login to GitHub Container Registry' - uses: docker/login-action@v1 + uses: docker/login-action@main with: registry: ghcr.io username: ${{github.actor}} From 19d983fd4fc3a9352205a66312d295a940747b12 Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:22:41 +0100 Subject: [PATCH 06/12] update to docker login action v3 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 876b9ea..7027c55 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: - name: 'Pull Code' uses: actions/checkout@main - name: 'Login to GitHub Container Registry' - uses: docker/login-action@main + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{github.actor}} From b959e657b96b72a8eb420a29a68fcd4aed37bd2d Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:25:32 +0100 Subject: [PATCH 07/12] use GITHUB_REPOSITORY_OWNER variable when building and pushing the image --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7027c55..0d0e1cf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,5 +19,5 @@ jobs: password: ${{secrets.GITHUB_TOKEN}} - name: 'Build Inventory Image' run: | - docker build . --tag ghcr.io/nohn/downdetector-exporter:latest - docker push ghcr.io/nohn/downdetector-exporter:latest + docker build . --tag ghcr.io/${{GITHUB_REPOSITORY_OWNER}}/downdetector-exporter:latest + docker push ghcr.io/${{GITHUB_REPOSITORY_OWNER}}/downdetector-exporter:latest From d20798c0ed70ef27ef8786cd2cb9db07c8214d31 Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:26:26 +0100 Subject: [PATCH 08/12] use GITHUB_REPOSITORY_OWNER variable when building and pushing the image --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0d0e1cf..4876366 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,5 +19,5 @@ jobs: password: ${{secrets.GITHUB_TOKEN}} - name: 'Build Inventory Image' run: | - docker build . --tag ghcr.io/${{GITHUB_REPOSITORY_OWNER}}/downdetector-exporter:latest - docker push ghcr.io/${{GITHUB_REPOSITORY_OWNER}}/downdetector-exporter:latest + docker build . --tag ghcr.io/${{ vars.GITHUB_REPOSITORY_OWNER }}/downdetector-exporter:latest + docker push ghcr.io/${{ vars.GITHUB_REPOSITORY_OWNER }}/downdetector-exporter:latest From 996b9012b886b94ccba83c1ee03c0dd04191ad6a Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:27:14 +0100 Subject: [PATCH 09/12] use GITHUB_REPOSITORY_OWNER variable when building and pushing the image --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4876366..1cf59bd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,5 +19,5 @@ jobs: password: ${{secrets.GITHUB_TOKEN}} - name: 'Build Inventory Image' run: | - docker build . --tag ghcr.io/${{ vars.GITHUB_REPOSITORY_OWNER }}/downdetector-exporter:latest - docker push ghcr.io/${{ vars.GITHUB_REPOSITORY_OWNER }}/downdetector-exporter:latest + docker build . --tag ghcr.io/$GITHUB_REPOSITORY_OWNER/downdetector-exporter:latest + docker push ghcr.io/$GITHUB_REPOSITORY_OWNER/downdetector-exporter:latest From cb442b0dcb2d2025916e59675f595ce5942220c7 Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:32:25 +0100 Subject: [PATCH 10/12] stop build test branches --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1cf59bd..bfdb4c9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ master, dockerfile ] + branches: [ master ] pull_request: jobs: From 9cda152f04434d5cddf6d8cab1c158122cadb917 Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 15:36:58 +0100 Subject: [PATCH 11/12] * Add Dockerfile * Add docker-compose and Kubernetes usage examples * Build Docker image and push to ghcr.io with Github Actions (contributes to #2) * Ignore backup files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ad2d307..e10297b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ downdetector-credentials.yaml downdetector-exporter +*~ \ No newline at end of file From ae100fadb61aacac9d4f552c25132d183d304c9b Mon Sep 17 00:00:00 2001 From: Sebastian Nohn Date: Fri, 3 Nov 2023 17:16:11 +0100 Subject: [PATCH 12/12] remove references to kompose --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 1427809..91fa61a 100644 --- a/README.md +++ b/README.md @@ -134,19 +134,11 @@ Example of running in kubernetes: apiVersion: apps/v1 kind: Deployment metadata: - labels: - io.kompose.service: downdetector-exporter name: downdetector-exporter spec: replicas: 1 - selector: - matchLabels: - io.kompose.service: downdetector-exporter strategy: {} template: - metadata: - labels: - io.kompose.service: downdetector-exporter spec: containers: - env: