Skip to content

Commit

Permalink
feat: docker build
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Gerber <github@gerber.uno>
  • Loading branch information
svengerber committed Mar 7, 2023
1 parent 6f40378 commit 507a4eb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion cmd/pusher/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func main() {
return c.SendString("OK")
})

app.Listen(":" + util.ListenPort)
app.Listen(":8080")
}
7 changes: 0 additions & 7 deletions internal/util/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"errors"
"os"
"net/url"
"log"
)

var (
UptimeKumaURL string
ListenPort string
)

// LoadEnv loads OS environment variables
Expand All @@ -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
}

0 comments on commit 507a4eb

Please sign in to comment.