From fc94dc385d61f0ad7d51e702dcc1c52f3fb9166c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ma=C5=A1ek?= Date: Sun, 12 Jan 2025 15:32:12 +0100 Subject: [PATCH] split test/release workflow --- .github/workflows/go.yml | 28 --------- .github/workflows/release.yml | 62 +++++++++++++++++++ .github/workflows/{docker.yml => testing.yml} | 25 ++++++-- Dockerfile | 21 +++---- README-dev.md | 6 +- compose.yaml | 5 +- conf/config.default.yaml | 4 +- 7 files changed, 94 insertions(+), 57 deletions(-) delete mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/release.yml rename .github/workflows/{docker.yml => testing.yml} (56%) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 6092f4a..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,28 +0,0 @@ -# This workflow will build a golang project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go - -name: Go - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.23' - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -v ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..00c9501 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/.github/workflows/docker.yml b/.github/workflows/testing.yml similarity index 56% rename from .github/workflows/docker.yml rename to .github/workflows/testing.yml index 0cc82e1..8e25879 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/testing.yml @@ -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: @@ -7,14 +9,23 @@ 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 }} @@ -22,4 +33,6 @@ jobs: 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 diff --git a/Dockerfile b/Dockerfile index bcab960..60a4b38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README-dev.md b/README-dev.md index b45d3fa..51ef579 100644 --- a/README-dev.md +++ b/README-dev.md @@ -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 @@ -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 @@ -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 diff --git a/compose.yaml b/compose.yaml index 195113e..8bf23b3 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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 diff --git a/conf/config.default.yaml b/conf/config.default.yaml index 9a98576..0fa5fff 100644 --- a/conf/config.default.yaml +++ b/conf/config.default.yaml @@ -1,6 +1,6 @@ services: - example-heartbeat-service: - example-web-service: + example-backup-job: + example-website: url: "" email: