Skip to content

Commit

Permalink
docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Aug 4, 2023
1 parent 52bbdba commit 20c8dba
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 11 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Deploy
on:
push:
branches:
- main
tags:
- 'v*'

jobs:
noaalerts:
name: Docker Build
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Environment
id: vars
run: |
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
bbengfort/noaalerts
tags: |
type=semver,pattern={{raw}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=,suffix=,format=short
- name: Setup QEMU
uses: docker/setup-qemu-action@v1

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and Push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_REVISION=${{ steps.vars.outputs.revision }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Tests
on:
push:
branches:
Expand Down
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Dynamic Builds
ARG BUILDER_IMAGE=golang:1.20-buster
ARG FINAL_IMAGE=debian:buster-slim

# Build Stage
FROM ${BUILDER_IMAGE} AS builder

# Build Args
ARG GIT_REVISION=""

# Ensure ca-certificates are up to date on the image
RUN update-ca-certificates

# Use modules for dependencies
WORKDIR $GOPATH/src/github.com/bbengfort/noaalert

COPY go.mod .
COPY go.sum .

ENV CGO_ENABLED=0
ENV GO111MODULE=on
RUN go mod download
RUN go mod verify

# Copy package
COPY . .

# Build binary
RUN go build -v -o /go/bin/noaalert -ldflags="-X 'github.com/bbengfort/noaalert.GitVersion=${GIT_REVISION}'" ./cmd/noaalert

# Final Stage
FROM ${FINAL_IMAGE} AS final

LABEL maintainer="Benjamin Bengfort <[email protected]>"
LABEL description="Converts NOAA Severe Weather Alerts API requests into real time events"

# Ensure ca-certificates are up to date
RUN set -x && apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*

# Copy the binary to the production image from the builder stage
COPY --from=builder /go/bin/noaalert /usr/local/bin/noaalert

CMD [ "/usr/local/bin/noaalert", "publish" ]
51 changes: 42 additions & 9 deletions cmd/noaalert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"fmt"
"os"
"text/tabwriter"
"time"

"github.com/bbengfort/noaalert"
"github.com/joho/godotenv"
confire "github.com/rotationalio/confire/usage"
"github.com/rs/zerolog/log"
cli "github.com/urfave/cli/v2"
)
Expand All @@ -22,19 +24,35 @@ func main() {
app.Usage = "publish NOAA weather alerts to Ensign"
app.Commands = []*cli.Command{
{
Name: "publish",
Usage: "run the publisher daemon to fetch alerts from the NOAA API",
Action: publish,
Name: "publish",
Usage: "run the publisher daemon to fetch alerts from the NOAA API",
Category: "server",
Action: publish,
},
{
Name: "subscribe",
Usage: "subscribe to NOAA alerts on Ensign",
Action: subscribe,
Name: "subscribe",
Category: "utility",
Usage: "subscribe to NOAA alerts on Ensign",
Action: subscribe,
},
{
Name: "alerts",
Usage: "get active NOAA alerts",
Action: alerts,
Name: "alerts",
Category: "utility",
Usage: "get active NOAA alerts",
Action: alerts,
},
{
Name: "config",
Usage: "print noaalerts configuration guide",
Category: "utility",
Action: usage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "list",
Aliases: []string{"l"},
Usage: "print in list mode instead of table mode",
},
},
},
}

Expand Down Expand Up @@ -111,3 +129,18 @@ func alerts(c *cli.Context) (err error) {
}
return nil
}

func usage(c *cli.Context) (err error) {
tabs := tabwriter.NewWriter(os.Stdout, 1, 0, 4, ' ', 0)
format := confire.DefaultTableFormat
if c.Bool("list") {
format = confire.DefaultListFormat
}

var conf noaalert.Config
if err := confire.Usagef("ensign", &conf, tabs, format); err != nil {
return cli.Exit(err, 1)
}
tabs.Flush()
return nil
}
13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3"
services:
publisher:
build:
context: .
dockerfile: ./
args:
GIT_REVISION: ${GIT_REVISION}
image: bbengfort/noaalerts
init: true
environment:
- ENSIGN_CLIENT_ID
- ENSIGN_CLEINT_SECRET
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
VersionReleaseNumber = 1
)

// Set the GitVersion via -ldflags="-X 'github.com/rotationalio/ensign/pkg.GitVersion=$(git rev-parse --short HEAD)'"
// Set the GitVersion via -ldflags="-X 'github.com/bbengfort/noaalert.GitVersion=$(git rev-parse --short HEAD)'"
var GitVersion string

// Version returns the semantic version for the current build.
Expand Down

0 comments on commit 20c8dba

Please sign in to comment.