Skip to content

Commit

Permalink
add docker build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hehu80 committed Sep 13, 2024
1 parent 50127a9 commit 2f75136
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Docker image and publish to GHCR

on:
push:
branches: [ main ]
tags: [ v* ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: hbtgmbh/air-pollution-service
BUILD_ID: ${{github.run_number}}

jobs:
test:
name: Test and lint
uses: HBTGmbH/air-pollution-service/.github/workflows/test.yml@main

build:
runs-on: ubuntu-latest
needs: [test]

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_ID }} .

- name: Push Docker image to Docker Hub
run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_ID }}
21 changes: 13 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
name: Test
on: [push]

on:
push:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.22.x' ]

steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
go-version: '1.22.x'

- name: Install Dependencies
run: go get ./...

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

- name: Run tests
run: go test ./... -json > TestResults-${{ matrix.go-version }}.json
run: go test ./... -json > TestResults-.json

- name: Upload test results
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: Go-results-${{ matrix.go-version }}
path: TestResults-${{ matrix.go-version }}.json
name: Go-results
path: TestResults.json
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ WORKDIR /air-pollution-service

RUN apk add --no-cache gcc musl-dev

COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go mod tidy
RUN go get ./...

RUN go build -ldflags '-w -s' -a -o ./bin/server ./cmd/server

Expand Down

0 comments on commit 2f75136

Please sign in to comment.