This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from ingrammicro/release/mirage
Release/mirage
- Loading branch information
Showing
13 changed files
with
493 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ _vendor* | |
coverage.txt | ||
profile.out | ||
.idea/* | ||
.idea/**/* | ||
.idea/**/* | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
builds: | ||
- binary: cio | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- windows | ||
- darwin | ||
- linux | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
archives: | ||
- format: binary | ||
name_template: "{{ .ProjectName }}.{{ .Version }}.{{ .Arch }}.{{ .Os }}" | ||
checksum: | ||
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt' | ||
release: | ||
prerelease: auto | ||
name_template: "{{.ProjectName}} {{.Tag}}" | ||
snapshot: | ||
name_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ spec: | |
templateRef: | ||
name: workflow-template-sonar-template-1.1 | ||
template: go-dependency-track | ||
when: "('{{workflow.parameters.branch}}' =~ '^v[0-9\\.]+$')" | ||
when: "('{{workflow.parameters.branch}}' =~ '^v[0-9\\.]+$') || ('{{workflow.parameters.branch}}' == 'develop')" | ||
|
||
- name: go-build | ||
dependencies: [dependencies] | ||
|
@@ -90,7 +90,7 @@ spec: | |
- name: test_path | ||
value: . | ||
- name: go-image | ||
value: golang:1.16 | ||
value: golang:1.18.3 | ||
when: "{{workflow.parameters.skip_tests}} == false" | ||
|
||
- name: sonar-branch-analysis | ||
|
@@ -139,12 +139,20 @@ spec: | |
optional: true | ||
when: "('{{workflow.parameters.pull_request}}' =~ '^[0-9]+$')" | ||
|
||
- name: goreleaser | ||
dependencies: [go-build] | ||
template: goreleaser | ||
arguments: | ||
artifacts: | ||
- name: src | ||
from: "{{tasks.dependencies.outputs.artifacts.src}}" | ||
when: "'{{workflow.parameters.branch}}' =~ '^v[0-9\\.]+'" | ||
|
||
- name: go-build | ||
inputs: | ||
parameters: | ||
- name: go-image | ||
value: golang:1.16 | ||
value: golang:1.18.3 | ||
- name: notifiable_commits | ||
- name: source_mountpath | ||
value: /usr/src | ||
|
@@ -223,3 +231,38 @@ spec: | |
cpu: 900m | ||
limits: | ||
cpu: 900m | ||
|
||
- name: goreleaser | ||
inputs: | ||
parameters: | ||
- name: go-image | ||
value: golang:1.18.3 | ||
artifacts: | ||
- name: src | ||
path: "/src" | ||
s3: | ||
endpoint: local-minio-service:9000 | ||
bucket: argo-workflow | ||
insecure: true | ||
key: "{{workflow.uid}}/src.tgz" | ||
accessKeySecret: | ||
name: s3-credentials-generated-by-kustomize | ||
key: S3_ACCESS_KEY_ID | ||
secretKeySecret: | ||
name: s3-credentials-generated-by-kustomize | ||
key: S3_SECRET_ACCESS_KEY | ||
script: | ||
image: "{{inputs.parameters.go-image}}" | ||
env: | ||
- name: GITHUB_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
name: github-token | ||
key: token | ||
command: [sh] | ||
source: | | ||
cd /src | ||
apk add --no-cache git | ||
go install github.com/goreleaser/[email protected] | ||
export GITHUB_TOKEN="${GITHUB_TOKEN}" | ||
goreleaser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package bootstrapping | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/ingrammicro/cio/api/blueprint" | ||
"github.com/ingrammicro/cio/api/types" | ||
"github.com/ingrammicro/cio/utils/format" | ||
log "github.com/sirupsen/logrus" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const ( | ||
inventoryFile = "inventory.yml" | ||
variableFile = "variables.yml" | ||
ansibleScript = "apply.sh" | ||
) | ||
|
||
// Subsidiary routine for commands processing | ||
func applyAnsiblePolicyfiles( | ||
ctx context.Context, | ||
blueprintConfig *types.BootstrappingConfiguration, | ||
bootstrappingSvc *blueprint.BootstrappingService, | ||
bsProcess *bootstrappingProcess, | ||
formatter format.Formatter, | ||
) error { | ||
err := prepareAnsibleInventory(ctx, bsProcess) | ||
if err != nil { | ||
formatter.PrintError("couldn't prepare inventory:", err) | ||
return err | ||
} | ||
err = prepareAnsibleVariables(ctx, bsProcess) | ||
if err != nil { | ||
formatter.PrintError("couldn't prepare variables:", err) | ||
return err | ||
} | ||
err = processAnsiblePolicyfiles(blueprintConfig, bootstrappingSvc, bsProcess) | ||
if err != nil { | ||
formatter.PrintError("couldn't process policyfiles:", err) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func prepareAnsibleInventory(ctx context.Context, bsProcess *bootstrappingProcess) error { | ||
log.Debug("prepareAnsibleInventory") | ||
file, err := os.Create(inventoryFilePath(bsProcess.directoryPath)) | ||
if err != nil { | ||
return fmt.Errorf("opening inventory file to write: %w", err) | ||
} | ||
defer file.Close() | ||
inventory := map[string]interface{}{ | ||
"all": map[string]interface{}{ | ||
"hosts": map[string]interface{}{ | ||
"localhost": map[string]interface{}{ | ||
"ansible_connection": "local", | ||
}, | ||
}, | ||
}, | ||
} | ||
encoder := yaml.NewEncoder(file) | ||
defer encoder.Close() | ||
err = encoder.Encode(inventory) | ||
if err != nil { | ||
return fmt.Errorf("encoding inventory: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func prepareAnsibleVariables(ctx context.Context, bsProcess *bootstrappingProcess) error { | ||
log.Debug("prepareAnsibleVariables") | ||
file, err := os.Create(variableFilePath(bsProcess.directoryPath)) | ||
if err != nil { | ||
return fmt.Errorf("opening variable file to write: %w", err) | ||
} | ||
defer file.Close() | ||
encoder := yaml.NewEncoder(file) | ||
defer encoder.Close() | ||
err = encoder.Encode(bsProcess.attributes.rawData) | ||
if err != nil { | ||
return fmt.Errorf("encoding variables: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func inventoryFilePath(dir string) string { | ||
return filepath.Join(dir, inventoryFile) | ||
} | ||
|
||
func variableFilePath(dir string) string { | ||
return filepath.Join(dir, variableFile) | ||
} | ||
|
||
// processAnsiblePolicyfiles applies for each policy the required ansible-galaxy and ansible-playbook commands, reporting in bunches of N lines | ||
func processAnsiblePolicyfiles(blueprintConfig *types.BootstrappingConfiguration, bootstrappingSvc *blueprint.BootstrappingService, bsProcess *bootstrappingProcess) error { | ||
log.Debug("processAnsiblePolicyfiles") | ||
for _, bsPolicyfile := range bsProcess.policyfiles { | ||
policyfileDir := bsPolicyfile.Path(bsProcess.directoryPath) | ||
command := fmt.Sprintf( | ||
"cd %s && sh %s %s %s", | ||
policyfileDir, | ||
ansibleScript, inventoryFilePath(bsProcess.directoryPath), variableFilePath(bsProcess.directoryPath)) | ||
log.Debug(command) | ||
bsProcess.cmsVersion = "" | ||
// Custom method for chunks processing | ||
fn := getBootstrapLogReporter(bootstrappingSvc, bsProcess, blueprintConfig) | ||
if err := runCommand(fn, command, bsProcess.thresholdLines); err != nil { | ||
return err | ||
} | ||
bsProcess.appliedPolicyfileRevisionIDs[bsPolicyfile.ID] = bsPolicyfile.RevisionID | ||
} | ||
return nil | ||
} |
Oops, something went wrong.