Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 664ba2c

Browse files
committed
Initial commit
Signed-off-by: Christian Dupuis <[email protected]>
0 parents  commit 664ba2c

28 files changed

+6040
-0
lines changed

.github/workflows/docker-publish.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Docker
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches: ["main"]
11+
# Publish semver tags as releases.
12+
tags: ["v*.*.*"]
13+
pull_request:
14+
branches: ["main"]
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
IMAGE_NAME: ${{ github.repository }}
21+
SHA: ${{ github.event.pull_request.head.sha || github.event.after }}
22+
DOCKERFILE_PATH: Dockerfile
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
packages: write
30+
# This is used to complete the identity challenge
31+
# with sigstore/fulcio when running outside of PRs.
32+
id-token: write
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v3
37+
with:
38+
ref: ${{ env.SHA }}
39+
40+
# Workaround: https://github.com/docker/build-push-action/issues/461
41+
- name: Setup Docker buildx
42+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
43+
44+
# Login against a Docker registry except on PR
45+
# https://github.com/docker/login-action
46+
- name: Log into registry
47+
if: github.event_name != 'pull_request'
48+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
# Extract metadata (tags, labels) for Docker
55+
# https://github.com/docker/metadata-action
56+
- name: Extract Docker metadata
57+
id: meta
58+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
59+
with:
60+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
61+
labels: |
62+
org.opencontainers.image.revision=${{ env.SHA }}
63+
com.docker.image.source.entrypoint=${{ env.DOCKERFILE_PATH }}
64+
65+
# Build and push Docker image with Buildx (don't push on PR)
66+
# https://github.com/docker/build-push-action
67+
- name: Build and push Docker image on Push
68+
if: ${{ github.event_name != 'pull_request' }}
69+
id: build-and-push
70+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
71+
with:
72+
platforms: "linux/amd64,linux/arm64"
73+
context: .
74+
file: ${{ env.DOCKERFILE_PATH }}
75+
push: true
76+
load: false
77+
tags: ${{ steps.meta.outputs.tags }}
78+
labels: ${{ steps.meta.outputs.labels }}
79+
80+
- name: Build and push Docker image on PR
81+
if: ${{ github.event_name == 'pull_request' }}
82+
id: build-and-push-pr
83+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
84+
with:
85+
context: .
86+
file: ${{ env.DOCKERFILE_PATH }}
87+
push: false
88+
load: true
89+
tags: ${{ steps.meta.outputs.tags }}
90+
labels: ${{ steps.meta.outputs.labels }}
91+
92+
# Extract SBOMs for images that are not getting pushed to the registry
93+
- name: Extract and upload SBOM
94+
if: ${{ github.event_name == 'pull_request' }}
95+
id: sbom
96+
uses: atomist-skills/index-image-action@main
97+
with:
98+
image: ${{ steps.meta.outputs.tags }}
99+
api-key: ${{ secrets.ATOMIST_API_KEY }}
100+
workspace: ${{ secrets.ATOMIST_WORKSPACE }}

.github/workflows/go.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v3
18+
with:
19+
go-version: 1.19
20+
21+
- name: Build
22+
run: go build -v
23+
24+
- name: Test
25+
run: go test -v

.github/workflows/goreleaser.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
goreleaser:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: 1.19
21+
22+
- name: Run GoReleaser
23+
uses: goreleaser/goreleaser-action@v3
24+
with:
25+
distribution: goreleaser
26+
args: release --rm-dist
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.atomist
2+
dist/
3+
.idea/
4+
index-cli-plugin
5+
/sbom.json

.goreleaser.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
release:
2+
prerelease: auto
3+
draft: true
4+
5+
builds:
6+
- binary: &binary docker-index
7+
goos:
8+
- linux
9+
- darwin
10+
- windows
11+
goarch:
12+
- amd64
13+
- arm64
14+
# set the modified timestamp on the output binary to the git timestamp to ensure a reproducible build
15+
mod_timestamp: &build-timestamp '{{ .CommitTimestamp }}'
16+
env: &build-env
17+
- CGO_ENABLED=0
18+
ldflags: &build-ldflags |
19+
-w
20+
-s
21+
-extldflags '-static'
22+
-X github.com/docker/index-cli-plugin/internal.version={{.Version}}
23+
-X github.com/docker/index-cli-plugin/internal.commit={{.Commit}}
24+
25+
archives:
26+
- format: tar.gz
27+
format_overrides:
28+
- goos: windows
29+
format: zip

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# build stage
2+
FROM golang:1.19-alpine3.16@sha256:0eb08c89ab1b0c638a9fe2780f7ae3ab18f6ecda2c76b908e09eb8073912045d as build
3+
4+
RUN apk add --no-cache git build-base ca-certificates
5+
6+
WORKDIR /app
7+
8+
COPY go.mod ./
9+
COPY go.sum ./
10+
11+
RUN go mod download
12+
13+
COPY . ./
14+
15+
# RUN go test
16+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -trimpath
17+
18+
# runtime stage
19+
FROM scratch
20+
21+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
22+
COPY --from=build /app/index-cli-plugin /index-cli-plugin
23+
24+
ENTRYPOINT ["/index-cli-plugin"]
25+
CMD ["--help"]

0 commit comments

Comments
 (0)