From 507a4eb52164657d740be29a78b3ad305d1f6570 Mon Sep 17 00:00:00 2001 From: Sven Gerber Date: Tue, 7 Mar 2023 20:39:31 +0100 Subject: [PATCH] feat: docker build Signed-off-by: Sven Gerber --- .github/workflows/release.yml | 50 +++++++++++++++++++++++++++++++++++ Dockerfile | 11 ++++++++ cmd/pusher/pusher.go | 2 +- internal/util/env.go | 7 ----- 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e1a199b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Create and publish a Docker image + +on: + push: + tags: [ '*' ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a850146 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.20.1 as build +WORKDIR /go/src/github.com/natrontech/alertmanager-uptime-kuma-push +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o alertmanager-uptime-kuma-push ./cmd/pusher + +FROM alpine:latest +RUN apk --no-cache add ca-certificates +WORKDIR /root/ +COPY --from=build /go/src/github.com/natrontech/alertmanager-uptime-kuma-push/alertmanager-uptime-kuma-push ./ +EXPOSE 8080 +CMD ["./alertmanager-uptime-kuma-push"] diff --git a/cmd/pusher/pusher.go b/cmd/pusher/pusher.go index 42cdf33..547d289 100644 --- a/cmd/pusher/pusher.go +++ b/cmd/pusher/pusher.go @@ -34,5 +34,5 @@ func main() { return c.SendString("OK") }) - app.Listen(":" + util.ListenPort) + app.Listen(":8080") } \ No newline at end of file diff --git a/internal/util/env.go b/internal/util/env.go index 7fce3a8..891cdc7 100644 --- a/internal/util/env.go +++ b/internal/util/env.go @@ -4,12 +4,10 @@ import ( "errors" "os" "net/url" - "log" ) var ( UptimeKumaURL string - ListenPort string ) // LoadEnv loads OS environment variables @@ -31,10 +29,5 @@ func LoadEnv() error { return errors.New("UPTIME_KUMA_URL has invalid scheme (http or https only)") } - if ListenPort = os.Getenv("LISTEN_PORT"); ListenPort == "" { - ListenPort = "3000" - log.Println("LISTEN_PORT not set, defaulting to 3000") - } - return nil } \ No newline at end of file