Skip to content

Commit

Permalink
Merge pull request #7 from jlamande/docker-build
Browse files Browse the repository at this point in the history
Add Docker build
  • Loading branch information
benc-uk authored Mar 14, 2021
2 parents 676630f + 3d9ab27 commit f0834d9
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Standard stuff
Dockerfile*
**/*Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
readme.md
**/readme.md
**/LICENSE
.vscode/

# Outputs, binaries etc
**/bin/
**/obj/
**/dist/

# Project specific folders
*.json
*.html
*.csv
reports/*
19 changes: 19 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
pull_request:
branches: [main]

env:
IMAGE_NAME: k6-reporter

jobs:
check:
name: "Run lint and format"
Expand All @@ -24,3 +27,19 @@ jobs:
- name: "Run build"
run: |
make build
build-image:
runs-on: ubuntu-latest
needs: [check]
steps:
- name: Checkout code
uses: actions/checkout@v2
# Build image
- name: Build the container image
run: make image IMAGE_REPO=$GITHUB_ACTOR/$IMAGE_NAME
# Only when pushing to default branch (e.g. master or main), then push image to registry
# - name: Push to container registry
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# run: |
# echo ${{ secrets.REGISTRY_PASSWORD }} | docker login $IMAGE_REG -u $GITHUB_ACTOR --password-stdin
# make push IMAGE_REPO=$GITHUB_ACTOR/$IMAGE_NAME
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.json
*.html
bin/
bin/*
*.csv
reports/*
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# =========================================
# === Stage 1: Build Golang k6-reporter ===
# =========================================
FROM golang:1.16 as builder
ARG VERSION="0.0.0"
ARG BUILD_INFO="Not set"

ENV CGO_ENABLED=0
RUN go version
WORKDIR /app
COPY . .
RUN make build

# ==========================================
# === Stage 2: Use exe in runtime image ====
# ==========================================
FROM scratch
WORKDIR /app
COPY --from=builder /app/bin/k6-reporter .
ENTRYPOINT ["./k6-reporter"]
21 changes: 19 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ VERSION := 1.2.0
BUILD_INFO := Manual build
SRC_DIR := ./cmd

.PHONY: help build lint lint-fix
# Most likely want to override these when calling `make image`
IMAGE_REG ?= ghcr.io
IMAGE_REPO ?= k6-reporter
IMAGE_TAG ?= latest
IMAGE_PREFIX := $(IMAGE_REG)/$(IMAGE_REPO)

.PHONY: help build lint lint-fix image push
.DEFAULT_GOAL := help

help: ## This help message :)
Expand All @@ -26,4 +32,15 @@ lint: ## Lint & format, will not fix but sets exit code on error

lint-fix: ## Lint & format, will try to fix errors and modify code
@which golangci-lint > /dev/null || go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run $(SRC_DIR)/... --fix
golangci-lint run $(SRC_DIR)/... --fix

################################################################################
image: ## Build container image
docker build --file ./Dockerfile \
--build-arg BUILD_INFO="$(BUILD_INFO)" \
--build-arg VERSION="$(VERSION)" \
--tag $(IMAGE_PREFIX):$(IMAGE_TAG) .

################################################################################
push: ## Push container image
docker push $(IMAGE_PREFIX):$(IMAGE_TAG)
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ make run

Alternatively run in place with `go run main.go`

## Container image

Build the container image :
```
make image
```

Run the image with for example a local `reports` folder :
```
docker run --rm -it -v $(pwd)/reports:/reports ghcr.io/k6-reporter -infile /reports/myresults.json -outfile /reports/report.html
```

# Screenshots

![](https://user-images.githubusercontent.com/14982936/104111528-d1bb6700-52da-11eb-9f98-27d207c7747b.png)
Expand Down

0 comments on commit f0834d9

Please sign in to comment.