From 44e16324f8b96a812490d3b08edac37f96ea79e2 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] add release workflow --- .github/workflows/release.yml | 65 +++++++++++++++++++++++++++++++++++ Dockerfile | 30 ++++++++++++---- README-dev.md | 6 ++-- compose.yaml | 5 ++- conf/config.default.yaml | 4 +-- test_docker.sh | 15 ++++---- 6 files changed, 103 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c579a2b --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/Dockerfile b/Dockerfile index bcab960..7c54073 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] 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: diff --git a/test_docker.sh b/test_docker.sh index 56cff3b..a5d8349 100755 --- a/test_docker.sh +++ b/test_docker.sh @@ -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} \ @@ -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"