Skip to content

Commit bdcc848

Browse files
committed
make patternizer into proper go CLI
- Replace basic Go app with Cobra-based CLI interface - New command structure: `patternizer init [--with-secrets]` - Container default command changed from script to CLI - Container multi-stage build with flexible configuration - 3-stage CI: lint/format → build/test → container build/push - Unit tests for core functionality (main_test.go) - Integration tests against real trivial-pattern repository - Updated README for consistency with changes
1 parent 8c07864 commit bdcc848

20 files changed

Lines changed: 1138 additions & 243 deletions

.github/workflows/ci.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
IMAGE_NAME: quay.io/dminnear/patternizer
15+
GO_VERSION: '1.24'
16+
GOLANGCI_LINT_VERSION: 'v2.1.6'
17+
18+
jobs:
19+
lint-and-format:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: ${{ env.GO_VERSION }}
29+
cache-dependency-path: src/go.sum
30+
31+
- name: Run gofmt
32+
run: |
33+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
34+
echo "The following files are not formatted:"
35+
gofmt -s -l .
36+
exit 1
37+
fi
38+
working-directory: ./src
39+
40+
- name: Run go vet
41+
run: go vet ./...
42+
working-directory: ./src
43+
44+
- name: Install golangci-lint
45+
run: |
46+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin ${{ env.GOLANGCI_LINT_VERSION }}
47+
48+
- name: Run golangci-lint
49+
run: $(go env GOPATH)/bin/golangci-lint run
50+
working-directory: ./src
51+
52+
build-and-test:
53+
runs-on: ubuntu-latest
54+
needs: lint-and-format
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Set up Go
60+
uses: actions/setup-go@v5
61+
with:
62+
go-version: ${{ env.GO_VERSION }}
63+
cache-dependency-path: src/go.sum
64+
65+
- name: Build binary
66+
run: go build -v -o patternizer .
67+
working-directory: ./src
68+
69+
- name: Run unit tests
70+
run: go test -v ./...
71+
working-directory: ./src
72+
73+
- name: Run integration tests
74+
run: ./test/integration_test.sh
75+
env:
76+
PATTERNIZER_BINARY: ./src/patternizer
77+
78+
build-container:
79+
runs-on: ubuntu-latest
80+
needs: build-and-test
81+
if: github.event_name == 'push'
82+
steps:
83+
- name: Checkout code
84+
uses: actions/checkout@v4
85+
86+
- name: Set up Docker Buildx
87+
uses: docker/setup-buildx-action@v3
88+
89+
- name: Log in to Quay.io
90+
uses: docker/login-action@v3
91+
with:
92+
registry: quay.io
93+
username: ${{ secrets.QUAY_USERNAME }}
94+
password: ${{ secrets.QUAY_PASSWORD }}
95+
96+
- name: Determine tags
97+
id: meta
98+
run: |
99+
echo "sha_tag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
100+
if [[ $GITHUB_REF == refs/tags/* ]]; then
101+
echo "is_tag=true" >> $GITHUB_OUTPUT
102+
echo "git_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
103+
else
104+
echo "is_tag=false" >> $GITHUB_OUTPUT
105+
fi
106+
107+
- name: Build and push Docker image
108+
uses: docker/build-push-action@v5
109+
with:
110+
context: .
111+
file: ./Containerfile
112+
push: true
113+
tags: |
114+
${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.sha_tag }}
115+
${{ steps.meta.outputs.is_tag == 'true' && format('{0}:{1}', env.IMAGE_NAME, steps.meta.outputs.git_tag) || '' }}
116+
${{ steps.meta.outputs.is_tag == 'false' && format('{0}:latest', env.IMAGE_NAME) || '' }}

.github/workflows/push-to-quay.yaml

Lines changed: 0 additions & 60 deletions
This file was deleted.

Containerfile

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1-
FROM registry.access.redhat.com/ubi10:10.0
1+
ARG GO_VERSION=1.24-alpine
2+
ARG ALPINE_VERSION=latest
23

3-
RUN dnf install -y git && dnf clean all
4+
# Build stage
5+
FROM docker.io/library/golang:${GO_VERSION} AS builder
46

5-
WORKDIR /wd
7+
WORKDIR /build
8+
9+
COPY src/go.mod src/go.sum .
10+
RUN go mod download
11+
12+
COPY src/ .
13+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o patternizer .
14+
15+
# Runtime stage
16+
FROM docker.io/library/alpine:${ALPINE_VERSION}
17+
18+
RUN apk --no-cache add git
19+
20+
COPY --from=builder /build/patternizer /usr/local/bin/patternizer
21+
22+
ARG PATTERNIZER_RESOURCES_DIR=/tmp/resources
23+
WORKDIR ${PATTERNIZER_RESOURCES_DIR}
624

725
COPY pattern.sh .
8-
COPY default-cmd.sh .
9-
COPY src/patternizer .
1026
COPY values-secret.yaml.template .
1127

12-
WORKDIR /repo
28+
ARG PATTERN_REPO_ROOT=/repo
29+
WORKDIR ${PATTERN_REPO_ROOT}
1330

14-
ENV USE_SECRETS=false
31+
ENV PATTERNIZER_RESOURCES_DIR=${PATTERNIZER_RESOURCES_DIR}
1532

16-
CMD ["/wd/default-cmd.sh"]
33+
ENTRYPOINT ["patternizer"]
34+
CMD ["help"]

0 commit comments

Comments
 (0)