Skip to content

Commit

Permalink
split test/release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmasek committed Jan 12, 2025
1 parent 319bb31 commit fc94dc3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 57 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/go.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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

- 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 }}
release/beacon-${GITHUB_REF_NAME}-linux-amd64
with:
push: true
file: ./Dockerfile
build-args: |
beacon_binary=release/beacon-${GITHUB_REF_NAME}-linux-amd64
tags: |
davidmasek/beacon:latest
davidmasek/beacon:${{ github.ref_name }}
25 changes: 19 additions & 6 deletions .github/workflows/docker.yml β†’ .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: Docker Image CI
# based on: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Testing

on:
push:
Expand All @@ -7,19 +9,30 @@ on:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build and test Docker image

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

- name: Build
run: go build -v ./...

- name: Go Tests
run: go test -v ./...

- name: Test inside container
env:
BEACON_EMAIL_SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
BEACON_EMAIL_SMTP_PORT: ${{ secrets.SMTP_PORT }}
BEACON_EMAIL_SMTP_USERNAME: ${{ secrets.SMTP_USERNAME }}
BEACON_EMAIL_SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
BEACON_EMAIL_SEND_TO: ${{ secrets.SEND_TO }}
BEACON_EMAIL_SENDER: ${{ secrets.SENDER }}
run: ./test_docker.sh
BEACON_BINARY: ./beacon
run: |
./test_docker.sh
21 changes: 7 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
FROM golang:1.23
FROM debian:bullseye-slim

WORKDIR /app

ENV GOCACHE=/root/.cache/go-build
ENV GOMODCACHE=/root/go/pkg/mod
ARG beacon_binary
ADD ${beacon_binary} /app/beacon

# 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
WORKDIR /app

COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
go build
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

0 comments on commit fc94dc3

Please sign in to comment.