Skip to content

Commit

Permalink
workflows: Update docker and test workflows (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpotter92 authored Aug 25, 2022
1 parent 0648265 commit 5ad4b61
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
pull_request:
push:
branches:
- "main"
- main
- dev
tags:
- "v*"

Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Publish images to dockerhub

on:
pull_request:
push:
branches:
- main
- dev
tags:
- "v*"

jobs:
docker:
name: Build and publish docker images
permissions:
packages: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.CI_DOCKERHUB_USERNAME }}
password: ${{ secrets.CI_DOCKERHUB_TOKEN }}

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
livepeer/data
ghcr.io/${{ github.repository }}
tags: |
type=schedule,pattern={{date 'YYYYMMDDHHmmss'}}
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
type=sha,format=long
type=semver,pattern={{version}},prefix=v
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{major}}.{{minor}},prefix=v
type=raw,value=${{ github.event.pull_request.head.ref }}
- name: Build and push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64, linux/arm64
push: true
build-args: |
version=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: notify livepeer-infra
run: curl -X POST https://holy-bread-207a.livepeer.workers.dev
43 changes: 0 additions & 43 deletions .github/workflows/publish.yaml

This file was deleted.

40 changes: 22 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
name: Test project
name: Trigger test suite for the project

on:
pull_request:
push:
branches:
- main
- dev

jobs:
test:
name: Trigger tests
name: Run tests with coverage reporting
runs-on: ubuntu-20.04
steps:
- name: Set up go
id: go
uses: actions/setup-go@v3
with:
go-version: 1.17

- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
# Check https://github.com/livepeer/go-livepeer/pull/1891
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Restore cache
uses: actions/cache@v3
- name: Set up go
id: go
uses: actions/setup-go@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
go-version: 1.17
cache: true
cache-dependency-path: go.sum

- name: Download dependencies
if: ${{ steps.go.outputs.cache-hit != 'true' }}
run: go mod download

- name: Run test suite
run: make test
- name: Run tests with coverage
run: go test ./... -v --race --covermode=atomic --coverprofile=coverage.out

- name: Upload coverage reports
uses: codecov/codecov-action@v3
with:
files: ./coverage.out
name: ${{ github.event.repository.name }}
verbose: true
27 changes: 14 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
FROM golang:1.16-alpine as builder
FROM golang:1.16-alpine as builder

RUN apk add --update make
RUN apk add --no-cache --update make

WORKDIR /app
WORKDIR /app

ENV GOFLAGS "-mod=readonly"
ENV GOFLAGS "-mod=readonly"

COPY go.mod go.sum ./
COPY go.mod go.sum ./

RUN go mod download
RUN go mod download

ARG version
RUN echo $version
ARG version

COPY . .
RUN echo $version

RUN make "version=$version"
COPY . .

FROM alpine
RUN make "version=$version"

WORKDIR /app
FROM alpine:latest

COPY --from=builder /app/build/* .
WORKDIR /app

COPY --from=builder /app/build/* /usr/local/bin/

0 comments on commit 5ad4b61

Please sign in to comment.