Skip to content

Commit

Permalink
Sample of building with ko
Browse files Browse the repository at this point in the history
  • Loading branch information
evankanderson committed Jun 29, 2023
1 parent 9ebffa3 commit 76501ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
36 changes: 2 additions & 34 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- uses: ko-build/[email protected]
- run: ko build --platform=all ./cmd/server --image-label=org.opencontainers.image.source=https://github.com/stacklok/mediator,org.opencontainers.image.title="Stacklok Mediator",org.opencontainers.image.licenses=Apache-2.0,org.opencontainers.image.vendor=Stacklok

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

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/stacklok/mediator
tags: |
type=semver,prefix=v,pattern={{version}}
type=sha,format=long
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.source=https://github.com/stacklok/mediator
org.opencontainers.image.title=Stacklok Mediator
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.vendor=Stacklok
- name: Build container images and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Only push to the registry if we're building the default branch
push: ${{ github.ref == 'refs/heads/main' }}
# ARM builds take a long time due to QEMU emulation. For PRs
# we only build amd64, and for the default branch we build both.
platforms: linux/amd64${{ github.event_name != 'pull_request' && ', linux/arm64' || '' }}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ make run-server

The application will be available on `http://localhost:8080` and gRPC on `localhost:8090`.

## Running the server under Compose:

**NOTE: the command will be either `docker-compose` or `podman-compose`, depending on which tool you installed.** You'll need to install the [`ko`](https://ko.build/install/) tool do the build and run.

```bash
# The repo to push to; "ko.local" is a special string meaning your local Docker repo
KO_DOCKER_REPO=ko.local
# ko adds YAML document separators at the end of each document, which docker-compose doesn't like
docker-compose -f <(ko resolve -f docker-compose.yaml | sed 's/^---$//') up
```

## Run the tests

Note that you need to have [started the database and loaded the schema](#initialize-the-database) before running the tests:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
ports:
- "8080:8080"
- "8090:8090"
image: ghcr.io/stacklok/mediator:latest
image: ko://github.com/stacklok/mediator/cmd/server
networks:
- app_net
depends_on:
Expand All @@ -40,7 +40,7 @@ services:
"--yes",
"--db-host=postgres",
]
image: ghcr.io/stacklok/mediator:latest
image: ko://github.com/stacklok/mediator/cmd/server
networks:
- app_net
deploy:
Expand Down

0 comments on commit 76501ff

Please sign in to comment.