Skip to content

Commit

Permalink
add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmasek committed Jan 12, 2025
1 parent 7caacba commit 44e1632
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 22 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build and Release

on:
push:
tags:
- 'v*'

jobs:
# build-and-release:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: '1.23'

# - name: Build binary
# run: |
# mkdir -p release
# GOOS=linux GOARCH=amd64 go build -o release/beacon-${GITHUB_REF_NAME}-linux-amd64

# - name: Create GitHub release
# uses: actions/create-release@v1
# with:
# tag_name: ${{ github.ref_name }}
# release_name: ${{ github.ref_name }}
# body: "Version: ${{ github.ref_name }}"
# draft: false
# prerelease: false
# token: ${{ secrets.GITHUB_TOKEN }}

# - name: Upload release binary
# uses: actions/upload-release-asset@v2
# with:
# repo_token: ${{ secrets.GITHUB_TOKEN }}
# release_id: ${{ steps.create_release.outputs.id }}
# asset_path: ./release/*
# asset_name: ${{ basename }}
# asset_content_type: application/octet-stream

docker-hub:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
env:
BEACON_VERSION: ${{ github.ref_name }}
with:
push: true
file: ./Dockerfile
tags: |
davidmasek/beacon:latest
davidmasek/beacon:${{ github.ref_name }}
30 changes: 24 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
FROM golang:1.23
# Stage 1: Builder
# -----------------------------------
FROM golang:1.23 AS builder

WORKDIR /app
WORKDIR /src

ENV GOCACHE=/root/.cache/go-build
ENV GOMODCACHE=/root/go/pkg/mod

# pre-copy/cache go.mod for pre-downloading dependencies and only re-downloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/go/pkg/mod \
go mod download && go mod verify

COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
go build
go build -o /app/beacon

# Stage 2: Main
# -----------------------------------
FROM debian:bookworm-slim AS main

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=builder /app/beacon /app/beacon

WORKDIR /app

ENV BEACON_DB=/app/beacon.db

ENTRYPOINT ["./beacon"]
CMD ["start"]
ENTRYPOINT ["/app/beacon"]
CMD ["start", "--config", "/app/beacon.yaml"]
6 changes: 2 additions & 4 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ This documents describes some internals, implementation details, and tries it's

You should start with the main [README](README.md).

TODO: json API responses
TODO: deploy and try how it works
TODO:

## 🚧 Feature list:
- 🟢 heartbeat listener
Expand Down Expand Up @@ -53,6 +50,7 @@ TODO:
- 🟢 main documentation done
- 🟡 needs some user-testing to make sure it makes sense
- 🟤 later: swagger API docs?
- 🟡 docker + dockerhub
- 🟢 notifications
- 🟢 email reporting
- 🟢 local HTML report
Expand All @@ -76,7 +74,7 @@ TODO:
- it might be good to not rely on external websites for unit testing, but not sure if it's worth it
- https://pkg.go.dev/testing#hdr-Main
- or just setup/teardown where needed...
-
- 🟡 TODO: look into code coverage



Expand Down
5 changes: 2 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ services:
ports:
- "8088:8088" # web GUI + API
volumes:
- ./config.sample.yaml:/root/beacon.yaml # config file
# Uncomment following line to persist DB
# - ./beacon.db:/root/beacon.db
- ./beacon.yaml:/app/beacon.yaml # config file
- ./beacon.db:/app/beacon.db # persist DB
4 changes: 2 additions & 2 deletions conf/config.default.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
example-heartbeat-service:
example-web-service:
example-backup-job:
example-website:
url: ""

email:
Expand Down
15 changes: 8 additions & 7 deletions test_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ set -o pipefail # Fail if any part of a pipeline fails
echo "Starting Beacon test."
echo "---------------------"

DOCKER_BUILDKIT=1 docker compose build beacon
echo "Build successful."
echo "-----------------"
echo "Building Docker image..."
echo "---------------------"
DOCKER_BUILDKIT=1 docker build -t beacon-test .

# try to read env file, but ignore it if it does not exist
# in CI the env will be set without this file
source ~/beacon.github.env || true
source ~/beacon.github.env || echo "Ignore missing file in CI"

docker compose run --rm \
-T \
echo "Running test..."
echo "---------------------"
docker run --rm \
--entrypoint bash \
-e BEACON_EMAIL_SMTP_SERVER=${BEACON_EMAIL_SMTP_SERVER} \
-e BEACON_EMAIL_SMTP_PORT=${BEACON_EMAIL_SMTP_PORT} \
Expand All @@ -26,7 +27,7 @@ docker compose run --rm \
-e BEACON_EMAIL_SEND_TO=${BEACON_EMAIL_SEND_TO} \
-e BEACON_EMAIL_SENDER=${BEACON_EMAIL_SENDER} \
-e BEACON_EMAIL_PREFIX='[staging]' \
beacon -c '
beacon-test -c '
set -e
/app/beacon start &
echo "executing POST"
Expand Down

0 comments on commit 44e1632

Please sign in to comment.