Skip to content

Commit

Permalink
Merge pull request #4 from golioth/feat/img-build
Browse files Browse the repository at this point in the history
Add CI workflow to build and publish images
  • Loading branch information
hasheddan committed Jun 30, 2023
2 parents f5acf08 + 811a5d8 commit 18aa0d8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI
on:
workflow_dispatch: {}
pull_request: {}
push:
branches:
- main

jobs:
build_publish:
name: Build and Publish
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Build and Export to Docker
uses: docker/build-push-action@v4
with:
context: .
file: ./images/xk6-coap/Dockerfile
platforms: linux/amd64
load: true
tags: goliothiot/xk6-coap

- name: Login to Dockerhub
uses: docker/login-action@v1
if: github.ref == 'refs/heads/main'
with:
username: goliothiot
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and Push to Dockerhub
uses: docker/build-push-action@v4
if: github.ref == 'refs/heads/main'
with:
context: .
file: ./images/xk6-coap/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: goliothiot/xk6-coap
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup:
ifeq (, $(shell which xk6))
@echo installing xk6
@go install go.k6.io/xk6/cmd/xk6@latest
@go install go.k6.io/xk6/cmd/xk6@v0.9.2
@echo xk6 successfully installed
endif

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@

## Getting Started

To get started, either build the `k6` binary or use the
[`goliothiot/xk6-coap`](https://hub.docker.com/repository/docker/goliothiot/xk6-coap)
image.

### Using the OCI Image

The quickest way to get started is by using the `goliothiot/xk6-coap` image,
which is [built](./images/xk6-coap/Dockerfile) from this repository and
published to DockerHub. Tests can be supplied when creating a container from the
image via a [bind mount](https://docs.docker.com/storage/bind-mounts/). For
example, the following command would run the [simple
example](./examples/simple.js) from this repository.

```
docker run -it --rm -v $(pwd)/examples/simple.js:/simple.js goliothiot/xk6-coap k6 run /simple.js --vus 10 --duration 5s
```

### Building a k6 Binary

Using `k6` extentions requires including the extension(s) in a `k6` build. The
[`xk6`](https://github.com/grafana/xk6) tool will handle executing the build,
and the `Makefile` in this repository will ensure that `xk6` is installed and
Expand Down
13 changes: 13 additions & 0 deletions images/xk6-coap/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# golang:1.20.5
FROM golang@sha256:6b3fa4b908676231b50acbbc00e84d8cee9c6ce072b1175c0ff352c57d8a612f as build

WORKDIR /build

COPY . ./

RUN make build

# gcr.io/distroless/static:nonroot
FROM gcr.io/distroless/static@sha256:9ecc53c269509f63c69a266168e4a687c7eb8c0cfd753bd8bfcaa4f58a90876f

COPY --from=build /build/k6 /usr/local/bin/k6

0 comments on commit 18aa0d8

Please sign in to comment.