Skip to content

Commit e721d0e

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 e721d0e

16 files changed

Lines changed: 930 additions & 243 deletions

.github/workflows/ci.yaml

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