Skip to content

Commit

Permalink
fix: add configuration for building container images (#230)
Browse files Browse the repository at this point in the history
* fix: add automation for building docker image

Signed-off-by: Florian Bauer <[email protected]>

* chore: rename container build job name

Signed-off-by: Florian Bauer <[email protected]>

* fix(Dockerfile): add entrypoint specification

Signed-off-by: Florian Bauer <[email protected]>

* doc: add container image usage to README.md

Signed-off-by: Florian Bauer <[email protected]>

* doc: adjust docker run command in README; set workdir for directory mapping to work

Signed-off-by: Florian Bauer <[email protected]>

* doc: more specific example for docker run usecase

Signed-off-by: Florian Bauer <[email protected]>

* doc: add license header to Dockerfile

Signed-off-by: Florian Bauer <[email protected]>

---------

Signed-off-by: Florian Bauer <[email protected]>
  • Loading branch information
fsrv-xyz authored Jan 10, 2025
1 parent 1bfe5e4 commit 81ffee4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:
permissions:
id-token: write
contents: write
packages: write

jobs:
release:
Expand Down Expand Up @@ -56,3 +57,38 @@ jobs:
dist/checksums.txt.pem
dist/checksums.txt.sig
dist/*.tar.gz
container_image:
runs-on: ubuntu-latest
steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

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

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:alpine AS build
RUN apk add --no-cache git make
WORKDIR /build
COPY . .
ENV CGO_ENABLED=0
RUN make build

FROM alpine:latest
COPY --from=build /build/dist/yamlfmt /bin/yamlfmt
WORKDIR /project
ENTRYPOINT ["/bin/yamlfmt"]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ yamlfmt -dstar **/*.{yaml,yml}
```
See the [doublestar](https://github.com/bmatcuk/doublestar) package for more information on this format.

Yamlfmt can also be used in ci/cd pipelines which supports running containers. The following snippet shows an example job for GitLab CI:
```yaml
yaml lint:
image: ghcr.io/google/yamlfmt:latest
before_script:
- apk add git
script:
- yamlfmt .
- git diff --exit-code
```
The Docker image can also be used to run yamlfmt without installing it on your system. Just mount the directory you want to format as a volume (`/project` is used by default):
```bash
docker run -v "$(pwd):/project" ghcr.io/google/yamlfmt:latest <yamlfmt args>
```

# Configuration File

The `yamlfmt` command can be configured through a yaml file called `.yamlfmt`. This file can live in your working directory, a path specified through a [CLI flag](./docs/command-usage.md#operation-flags), or in the standard global config path on your system (see docs for specifics).
Expand Down

0 comments on commit 81ffee4

Please sign in to comment.