Skip to content

Commit c353fdf

Browse files
committed
Initial Commit
Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com>
0 parents  commit c353fdf

50 files changed

Lines changed: 5224 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
# Publish semver tags as releases.
11+
tags: [ '*.*.*.*' ]
12+
13+
env:
14+
# Use docker.io for Docker Hub if empty
15+
REGISTRY: ghcr.io
16+
# github.repository as <account>/<repo>
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
20+
jobs:
21+
build:
22+
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
# This is used to complete the identity challenge
28+
# with sigstore/fulcio when running outside of PRs.
29+
id-token: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v3
34+
35+
# Install the cosign tool except on PR
36+
# https://github.com/sigstore/cosign-installer
37+
- name: Install cosign
38+
if: github.event_name != 'pull_request'
39+
uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
40+
with:
41+
cosign-release: 'v1.13.1'
42+
43+
44+
# Workaround: https://github.com/docker/build-push-action/issues/461
45+
- name: Setup Docker buildx
46+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
47+
48+
# Login against a Docker registry except on PR
49+
# https://github.com/docker/login-action
50+
- name: Log into registry ${{ env.REGISTRY }}
51+
if: github.event_name != 'pull_request'
52+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
53+
with:
54+
registry: ${{ env.REGISTRY }}
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
58+
# Extract metadata (tags, labels) for Docker
59+
# https://github.com/docker/metadata-action
60+
- name: Extract Docker metadata
61+
id: meta
62+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
63+
with:
64+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
65+
66+
# Build and push Docker image with Buildx (don't push on PR)
67+
# https://github.com/docker/build-push-action
68+
- name: Build and push Docker image
69+
id: build-and-push
70+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
71+
with:
72+
context: .
73+
push: ${{ github.event_name != 'pull_request' }}
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max
78+
79+
80+
# Sign the resulting Docker image digest except on PRs.
81+
# This will only write to the public Rekor transparency log when the Docker
82+
# repository is public to avoid leaking data. If you would like to publish
83+
# transparency data even for private images, pass --force to cosign below.
84+
# https://github.com/sigstore/cosign
85+
- name: Sign the published Docker image
86+
if: ${{ github.event_name != 'pull_request' }}
87+
env:
88+
COSIGN_EXPERIMENTAL: "true"
89+
# This step uses the identity token to provision an ephemeral certificate
90+
# against the sigstore community Fulcio instance.
91+
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
on:
2+
release:
3+
types: [created]
4+
5+
jobs:
6+
release-linux-amd64:
7+
name: release linux/amd64
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: wangyoucao577/go-release-action@v1.34
12+
with:
13+
github_token: ${{ secrets.GITHUB_TOKEN }}
14+
goos: linux
15+
goarch: amd64
16+
goversion: 1.19
17+
binary_name: create-cli
18+
19+
release-darwin-arm64:
20+
name: release darwin/arm64
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: wangyoucao577/go-release-action@v1.34
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
goos: darwin
28+
goarch: arm64
29+
goversion: 1.19
30+
binary_name: create-cli
31+
32+
release-darwin-amd64:
33+
name: release darwin/amd64
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v3
37+
- uses: wangyoucao577/go-release-action@v1.34
38+
with:
39+
github_token: ${{ secrets.GITHUB_TOKEN }}
40+
goos: darwin
41+
goarch: amd64
42+
goversion: 1.19
43+
binary_name: create-cli

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
23+
# create-cli binary
24+
create-cli
25+
26+
# exclude the folders created by the download command
27+
create-repositories

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.18-alpine AS base
2+
WORKDIR /app
3+
COPY . ./
4+
RUN go mod download
5+
RUN CGO_ENABLED=0 go build -o create-cli .
6+
7+
FROM alpine:3.16.2
8+
RUN apk add --no-cache tini
9+
WORKDIR /root/
10+
COPY --from=base /app/create-cli ./
11+
ENTRYPOINT ["/sbin/tini", "--", "./create-cli"]

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# create-cli
2+
3+
A command line client for CREATE.
4+
5+
## Releasing `create-cli`
6+
7+
In order to release the `create-cli`, simply create the correct release and tags via the release page. It is important that you also modify the `cmd/version.go` file to have the correct vesrion that you want to release. This isn't the best way of ensuring we set the correct versions for the `cli` but for now it will do.
8+
9+
Example:
10+
From:
11+
12+
```golang
13+
fmt.Println("create-cli 1.0.0.0")
14+
```
15+
16+
To:
17+
18+
```golang
19+
fmt.Println("create-cli 1.0.0.1")
20+
```
21+
22+
Once this has been committed to main alongside the changes associated with the new version, publish the new release and tag and the Github Actions workflow will ensure that the container is built and published to `ghcr.io/cd-create/create-cli:[VERSION]`, alongside the Binaries being attached to the Release Assets.

cmd/bootstrap.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
"create-cli/internal/concourse"
5+
"create-cli/internal/harbor"
6+
"create-cli/internal/keycloak"
7+
"create-cli/internal/sonarqube"
8+
"create-cli/internal/vault"
9+
"log"
10+
11+
"github.com/spf13/cobra"
12+
"github.com/spf13/viper"
13+
)
14+
15+
func Bootstrap(args []string) {
16+
keycloak.Keycloak()
17+
vault.Vault()
18+
sonarqube.SonarQube()
19+
concourse.Concourse()
20+
harbor.Harbor()
21+
log.Println("Bootstrap complete.")
22+
}
23+
24+
func init() {
25+
bootstrapCmd.Flags().StringVarP(&createUrl, "create-url", "", "", "The URL of CREATE (e.g. create.company.com")
26+
bootstrapCmd.MarkFlagRequired("create-url")
27+
viper.BindPFlag("create-url", bootstrapCmd.Flags().Lookup("create-url"))
28+
29+
rootCmd.AddCommand(bootstrapCmd)
30+
}
31+
32+
var bootstrapCmd = &cobra.Command{
33+
Use: "bootstrap",
34+
Short: "Bootstraps the initial tooling cluster by ensuring all tooling applications have been configured in the correct way ready for use.",
35+
Run: func(cmd *cobra.Command, args []string) {
36+
Bootstrap(args)
37+
},
38+
}

cmd/pre-install.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package cmd
2+
3+
import (
4+
"create-cli/internal/configure"
5+
"create-cli/internal/download"
6+
"create-cli/internal/push"
7+
"fmt"
8+
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
11+
)
12+
13+
var cloudProvider string
14+
var acmeRegistrationEmail string
15+
var backstageGitlabUserToken string
16+
var concourseGitlabUserToken string
17+
var gitlabGroup string
18+
var gitlabHost string
19+
var gitlabPATToken string
20+
21+
func init() {
22+
downloadFlags()
23+
configureFlags()
24+
pushFlags()
25+
26+
preInstallCmd.AddCommand(downloadCmd)
27+
preInstallCmd.AddCommand(configureCmd)
28+
preInstallCmd.AddCommand(pushCmd)
29+
rootCmd.AddCommand(preInstallCmd)
30+
}
31+
32+
func downloadFlags() {
33+
downloadCmd.Flags().StringVarP(&cloudProvider, "cloud-provider", "", "", "The Cloud Provider that CREATE will exist in")
34+
downloadCmd.MarkFlagRequired("cloud-provider")
35+
36+
// temporary whilst the repos are private. they will be open sourced and this won't be needed after that.
37+
downloadCmd.Flags().StringVarP(&personalAccessToken, "pat", "", "", "Personal Access Token for the Git Repository (Gitlab/GitHub)")
38+
downloadCmd.MarkFlagRequired("pat")
39+
}
40+
41+
func configureFlags() {
42+
configureCmd.Flags().StringVarP(&gitlabPATToken, "gitlab-pat-token", "", "", "The Personal Access Token belonging to User with Admin permissions to Gitlab Group.")
43+
configureCmd.MarkFlagRequired("gitlab-pat-token")
44+
45+
configureCmd.Flags().StringVarP(&createUrl, "create-url", "", "", "The URL of CREATE (e.g. create.company.com")
46+
configureCmd.MarkFlagRequired("create-url")
47+
48+
configureCmd.Flags().StringVarP(&acmeRegistrationEmail, "acme-reg-email", "", "", "The ACME registration email to use for LetsEncrypt certificates")
49+
configureCmd.MarkFlagRequired("acme-reg-email")
50+
51+
configureCmd.Flags().StringVarP(&backstageGitlabUserToken, "backstage-gitlab-token", "", "", "The Token belonging to the Backstage Gitlab user")
52+
configureCmd.MarkFlagRequired("backstage-gitlab-token")
53+
54+
configureCmd.Flags().StringVarP(&concourseGitlabUserToken, "concourse-gitlab-token", "", "", "The Token belonging to the Concourse Gitlab user")
55+
configureCmd.MarkFlagRequired("concourse-gitlab-token")
56+
57+
configureCmd.Flags().StringVarP(&gitlabHost, "gitlab-host", "", "gitlab.com", "The Gitlab host to which the CREATE Git repositories will live. Defaults to gitlab.com")
58+
59+
configureCmd.Flags().StringVarP(&gitlabGroup, "gitlab-group", "", "", "The group (or owner) to which the CREATE Git repositories will live. Example: 'group/subgroup' in 'gitlab.com/group/subgroup'")
60+
configureCmd.MarkFlagRequired("gitlab-group")
61+
}
62+
63+
func pushFlags() {
64+
pushCmd.Flags().StringVarP(&cloudProvider, "cloud-provider", "", "", "The Cloud Provider that CREATE will exist in")
65+
pushCmd.MarkFlagRequired("cloud-provider")
66+
67+
pushCmd.Flags().StringVarP(&personalAccessToken, "pat", "", "", "Personal Access Token for the Git Repository (Gitlab/GitHub)")
68+
pushCmd.MarkFlagRequired("pat")
69+
70+
pushCmd.Flags().StringVarP(&gitlabHost, "host", "", "gitlab.com", "The Gitlab host to push CREATE repositories into. Defaults to gitlab.com")
71+
72+
pushCmd.Flags().StringVarP(&gitlabGroup, "gitlab-group", "", "", "The Gitlab group to push CREATE repositories into. Example: 'subgroup' in 'group/subgroup'")
73+
pushCmd.MarkFlagRequired("gitlab-group")
74+
}
75+
76+
var preInstallCmd = &cobra.Command{
77+
Use: "pre-install",
78+
Short: "Runs actions that are focused on the pre-installation configuration phase of CREATE.",
79+
Args: cobra.MinimumNArgs(0),
80+
Run: func(cmd *cobra.Command, args []string) {
81+
fmt.Println("Error: must also specify a sub-command.")
82+
},
83+
}
84+
85+
var downloadCmd = &cobra.Command{
86+
Use: "download",
87+
Short: "Downloads all CREATE repositories via Git",
88+
Args: cobra.MinimumNArgs(0),
89+
PreRun: func(cmd *cobra.Command, args []string) {
90+
viper.BindPFlag("cloud-provider", cmd.Flags().Lookup("cloud-provider"))
91+
viper.BindPFlag("pat", cmd.Flags().Lookup("pat"))
92+
},
93+
Run: func(cmd *cobra.Command, args []string) {
94+
download.Download()
95+
},
96+
}
97+
98+
var configureCmd = &cobra.Command{
99+
Use: "configure",
100+
Short: "Configures clone repositories with generated values", // better description
101+
Args: cobra.MinimumNArgs(0),
102+
PreRun: func(cmd *cobra.Command, args []string) {
103+
viper.BindPFlag("gitlab-pat-token", cmd.Flags().Lookup("gitlab-pat-token"))
104+
viper.BindPFlag("create-url", cmd.Flags().Lookup("create-url"))
105+
viper.BindPFlag("acme-reg-email", cmd.Flags().Lookup("acme-reg-email"))
106+
viper.BindPFlag("backstage-gitlab-token", cmd.Flags().Lookup("backstage-gitlab-token"))
107+
viper.BindPFlag("concourse-gitlab-token", cmd.Flags().Lookup("concourse-gitlab-token"))
108+
viper.BindPFlag("gitlab-host", cmd.Flags().Lookup("gitlab-host"))
109+
viper.BindPFlag("gitlab-group", cmd.Flags().Lookup("gitlab-group"))
110+
},
111+
Run: func(cmd *cobra.Command, args []string) {
112+
configure.Configure()
113+
},
114+
}
115+
116+
var pushCmd = &cobra.Command{
117+
Use: "push",
118+
Short: "Pushes all repositories into upstream Git repository",
119+
Args: cobra.MinimumNArgs(0),
120+
PreRun: func(cmd *cobra.Command, args []string) {
121+
viper.BindPFlag("pat", cmd.Flags().Lookup("pat"))
122+
viper.BindPFlag("gitlab-host", cmd.Flags().Lookup("gitlab-host"))
123+
viper.BindPFlag("gitlab-group", cmd.Flags().Lookup("gitlab-group"))
124+
viper.BindPFlag("cloud-provider", cmd.Flags().Lookup("cloud-provider"))
125+
},
126+
Run: func(cmd *cobra.Command, args []string) {
127+
push.Push()
128+
},
129+
}

0 commit comments

Comments
 (0)