Skip to content

Commit bdc4f15

Browse files
authored
Add pipeline for build goss docker image (#909)
* Add pipeline for build goss docker image * use go version from project * adapt setting version to changed var from PR #892 * add docs
1 parent 99db7ab commit bdc4f15

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed

.github/workflows/docker-goss.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Docker image for Goss
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- "v*"
9+
workflow_dispatch:
10+
11+
env:
12+
PLATFORMS: "linux/amd64,linux/arm64"
13+
14+
jobs:
15+
goss:
16+
name: Build and push Docker image
17+
runs-on: ubuntu-latest
18+
permissions:
19+
packages: write
20+
contents: read
21+
security-events: write # To upload Trivy sarif files
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v3
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Login to GHCR
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.repository_owner }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: |
45+
ghcr.io/${{ github.repository_owner }}/goss
46+
47+
- name: Get latest git tag
48+
uses: actions-ecosystem/action-get-latest-tag@v1
49+
id: get-latest-tag
50+
51+
- name: Set short git commit SHA
52+
run: |
53+
calculatedSha=$(git rev-parse --short ${{ github.sha }})
54+
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
55+
56+
- name: Get the current version of Go from project.
57+
run: echo "GO_VERSION_FROM_PROJECT=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV
58+
59+
- name: Build master goss image
60+
if: github.ref_name == 'master'
61+
uses: docker/build-push-action@v5
62+
with:
63+
build-args: |
64+
GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }}
65+
GOSS_VERSION=${{ steps.get-latest-tag.outputs.tag }}-${{ github.ref_name }}+${{ env.COMMIT_SHORT_SHA }}
66+
context: .
67+
push: true
68+
tags: |
69+
ghcr.io/${{ github.repository_owner }}/goss:master
70+
labels: ${{ steps.meta.outputs.labels }}
71+
platforms: ${{ env.PLATFORMS }}
72+
73+
- name: Build release goss image
74+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
75+
uses: docker/build-push-action@v5
76+
with:
77+
build-args: |
78+
GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }}
79+
GOSS_VERSION=${{ github.ref_name }}
80+
context: .
81+
push: true
82+
tags: |
83+
ghcr.io/${{ github.repository_owner }}/goss:latest
84+
ghcr.io/${{ github.repository_owner }}/goss:${{ github.ref_name }}
85+
labels: ${{ steps.meta.outputs.labels }}
86+
platforms: ${{ env.PLATFORMS }}
87+
88+
- name: Run Trivy vulnerability scanner
89+
uses: aquasecurity/trivy-action@master
90+
with:
91+
image-ref: ghcr.io/${{ github.repository_owner }}/goss:master
92+
format: "sarif"
93+
output: "trivy-results.sarif"
94+
95+
- name: Upload Trivy scan results to GitHub Security tab
96+
uses: github/codeql-action/upload-sarif@v3
97+
with:
98+
sarif_file: "trivy-results.sarif"

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ARG GO_VERSION=1.21
2+
3+
FROM docker.io/golang:${GO_VERSION}-alpine AS base
4+
5+
ARG GOSS_VERSION=v0.0.0
6+
WORKDIR /build
7+
8+
RUN --mount=target=. \
9+
CGO_ENABLED=0 go build \
10+
-ldflags "-X github.com/goss-org/goss/util.Version=${GOSS_VERSION} -s -w" \
11+
-o "/release/goss" \
12+
./cmd/goss
13+
14+
FROM alpine:3.19
15+
16+
COPY --from=base /release/* /usr/bin/
17+
18+
RUN mkdir /goss
19+
VOLUME /goss

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ make build
9595

9696
[Full Documentation](https://github.com/goss-org/goss/blob/e73553f9c3065ac297499dafb4f8abef6acb24ad/docs/manual.md)
9797

98+
## Using the container image
99+
100+
[Using the Goss container image](docs/container_image.md)
101+
98102
## Quick start
99103

100104
<!-- --8<-- [start:quickstart] -->

docs/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ nav:
22
- Home: index.md
33
- installation.md
44
- quickstart.md
5+
- container_image.md
56
- Command Reference: cli.md
67
- The gossfile: gossfile.md
78
- migrations.md

docs/container_image.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Goss container image
2+
3+
## Dockerfiles
4+
5+
* [latest](https://github.com/goss-org/goss/blob/master/Dockerfile)
6+
7+
## Using the base image
8+
9+
This is a simple alpine image with Goss preinstalled on it.
10+
Can be used as a base image for your projects to allow for easy health checking.
11+
12+
### Mount example
13+
14+
Create the container
15+
16+
```sh
17+
docker run --name goss ghcr.io/goss-org/goss goss
18+
```
19+
20+
Create your container and mount goss
21+
22+
```sh
23+
docker run --rm -it --volumes-from goss --name weby nginx
24+
```
25+
26+
Run goss inside your container
27+
28+
```sh
29+
docker exec weby /goss/goss autoadd nginx
30+
```
31+
32+
### HEALTHCHECK example
33+
34+
```dockerfile
35+
FROM ghcr.io/goss-org/goss:latest
36+
37+
COPY goss/ /goss/
38+
HEALTHCHECK --interval=1s --timeout=6s CMD goss -g /goss/goss.yaml validate
39+
40+
# your stuff..
41+
```
42+
43+
### Startup delay example
44+
45+
```dockerfile
46+
FROM ghcr.io/goss-org/goss:latest
47+
48+
COPY goss/ /goss/
49+
50+
# Alternatively, the -r option can be set
51+
# using the GOSS_RETRY_TIMEOUT env variable
52+
CMD goss -g /goss/goss.yaml validate -r 5m && exec real_comand..
53+
```

0 commit comments

Comments
 (0)