Skip to content

Commit

Permalink
revert to multiple workflows for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmasek committed Jan 12, 2025
1 parent af3c788 commit 1351a87
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 48 deletions.
25 changes: 6 additions & 19 deletions .github/workflows/testing.yml → .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# based on: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Testing
name: Docker Image CI

on:
push:
Expand All @@ -9,30 +7,19 @@ on:
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: Go Tests
run: go test -v ./...

- name: Test inside container
- name: Build and test Docker image
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 }}
BEACON_BINARY: ./beacon
run: |
./test_docker.sh
run: ./test_docker.sh
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 ./...
34 changes: 19 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ on:
- 'v*'

jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# 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: 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: 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
Expand All @@ -41,6 +41,12 @@ jobs:
# 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:
Expand All @@ -54,8 +60,6 @@ jobs:
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 }}
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# Stage 1: Builder
# -----------------------------------
FROM golang:1.23 as builder
FROM golang:1.23 AS builder

WORKDIR /src

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

COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/go/pkg/mod \
go mod download && go mod verify

# Build the Go executable
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
go build -o /app/beacon

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

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl \
Expand Down
12 changes: 2 additions & 10 deletions test_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ set -o pipefail # Fail if any part of a pipeline fails
echo "Starting Beacon test."
echo "---------------------"

# BEACON_BINARY not set
if [ -z "$BEACON_BINARY" ]; then
echo "Building Beacon binary..."
echo "---------------------"
go build .
BEACON_BINARY=./beacon
fi

echo "Building Docker image with \"${BEACON_BINARY}\"..."
echo "Building Docker image..."
echo "---------------------"
DOCKER_BUILDKIT=1 docker build --build-arg beacon_binary="${BEACON_BINARY}" -t beacon-test .
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
Expand Down

0 comments on commit 1351a87

Please sign in to comment.