Skip to content

Commit

Permalink
Build and push Docker image on commit to main
Browse files Browse the repository at this point in the history
  • Loading branch information
vegarsti committed Jun 5, 2024
1 parent dfc27db commit 7ace045
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: "Build"

#on:
# push:
# branches:
# - main

on:
pull_request:
branches:
- main

jobs:
build:
name: "Build Docker image and push to Dockerhub"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- env:
GITHUB_TOKEN: ${{ secrets.DUNE_ENG_ACCESS_TOKEN }}
run: |
make image-build
make image-push
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.22-bookworm AS builder

RUN apt update && apt install -y curl make

ARG GITHUB_TOKEN

# first copy just enough to pull all dependencies, to cache this layer
COPY go.mod go.sum Makefile /app/
WORKDIR /app/
RUN git config --global url."https://dune-eng:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" \
&& make setup

# lint, build, etc..
COPY . /app/
RUN make build

FROM debian:bookworm-slim
RUN apt update \
&& apt install -y ca-certificates \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/dist/ /app/
ENTRYPOINT ["/app/duneapi"]
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.PHONY: all setup lint harvester test image-build image-push
.PHONY: all setup lint build test image-build image-push

APPLICATION := harvester
GITHUB_SHA ?= HEAD
REF_TAG := $(shell echo ${GITHUB_REF_NAME} | tr -cd '[:alnum:]')
IMAGE_TAG := ${ECR_REGISTRY}/${ECR_REPOSITORY}:${REF_TAG}-$(shell git rev-parse --short "${GITHUB_SHA}")-${GITHUB_RUN_NUMBER}
TEST_TIMEOUT := 10s

all: lint test harvester
all: lint test build

setup: bin/golangci-lint bin/gofumpt
go mod download
Expand All @@ -16,7 +16,7 @@ bin/golangci-lint:
bin/gofumpt: bin
GOBIN=$(PWD)/bin go install mvdan.cc/gofumpt@v0.6.0

harvester: lint cmd/main.go
build: lint cmd/main.go
go build -o harvester cmd/main.go

lint: bin/golangci-lint bin/gofumpt
Expand All @@ -37,5 +37,5 @@ image-build:
image-push: image-build
@echo "# Pushing harvester docker image..."
docker tag $(APPLICATION) ${IMAGE_TAG}
docker push ${IMAGE_TAG}
docker rmi ${IMAGE_TAG}
# docker push ${IMAGE_TAG}
# docker rmi ${IMAGE_TAG}

0 comments on commit 7ace045

Please sign in to comment.