-
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 #1 from bcgov-nr/initialCommit
CI workflow and intention file generator
- Loading branch information
Showing
19 changed files
with
13,232 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# git things | ||
.git | ||
.github | ||
|
||
# No docs | ||
*.md | ||
|
||
node_modules |
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,56 @@ | ||
name: Pull Request | ||
|
||
on: | ||
pull_request: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
# # Uncomment to view GitHub context object | ||
# view-context: | ||
# # https://docs.github.com/en/actions/learn-github-actions/contexts | ||
# name: View GitHub Context | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: Echo GitHub context | ||
# uses: satackey/action-js-inline@v0.0.2 | ||
# with: | ||
# script: | | ||
# const github = require('@actions/github'); | ||
# console.log(JSON.stringify(github, null, 2)); | ||
|
||
build-backend: | ||
name: Backend Image Build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./ | ||
push: true | ||
tags: ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.event.number }}-pr | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
build-args: | | ||
REPO_LOCATION= |
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,71 @@ | ||
name: Tag Main | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*' | ||
paths-ignore: | ||
- ".**" | ||
- "**.md" | ||
- "**.yml" | ||
- "**.yaml" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
# # Uncomment to view GitHub context object | ||
# view-context: | ||
# # https://docs.github.com/en/actions/learn-github-actions/contexts | ||
# name: View GitHub Context | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: Echo GitHub context | ||
# uses: satackey/action-js-inline@v0.0.2 | ||
# with: | ||
# script: | | ||
# const github = require('@actions/github'); | ||
# console.log(JSON.stringify(github, null, 2)); | ||
|
||
build-image: | ||
name: Build Image | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ github.repository }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Backend Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
build-args: | | ||
REPO_LOCATION= |
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,9 @@ | ||
**/*.vscode | ||
**/local.* | ||
**/.classpath | ||
**/.project | ||
**/.settings/ | ||
**/target/ | ||
**/Non-deliverables | ||
**/lib* | ||
**/node_modules/ |
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,18 @@ | ||
FROM node:21 | ||
|
||
ARG APP=app | ||
ARG HOME=/home/node | ||
|
||
ENV NPM_CONFIG_PREFIX=$HOME/.npm-global | ||
ENV PATH=$PATH:$HOME/.npm-global/bin | ||
|
||
RUN npm install -g yo@4.3.1 | ||
|
||
COPY --chown=node:node ./generator-nr-maven-build $HOME/$APP/ | ||
RUN cd $HOME/$APP/ && npm ci && npm link | ||
|
||
ENV HOME=/tmp | ||
WORKDIR /src | ||
VOLUME ["/src"] | ||
|
||
ENTRYPOINT ["yo"] |
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 |
---|---|---|
@@ -1 +1,26 @@ | ||
# nr-pipeline-template | ||
# nr-pipeline-template: | ||
> A central location for storing [Yeoman](http://yeoman.io) generators used for scaffolding applications that use the NR Broker | ||
> Currently consists of a single generator, nr-maven-build, used to generate the CI workflow and NR Broker intention files for building Java/Tomcat with Maven in GitHub | ||
Run the build script (optional for local testing): | ||
``` | ||
./build.sh | ||
``` | ||
|
||
Run the following command from the root of your application repository to generate your CI workflow and NR Broker intention files: | ||
``` | ||
podman run --rm -it -v $PWD:/src --userns keep-id ghcr.io/bcgov-nr/nr-pipeline-template:4-pr -- nr-maven-build | ||
``` | ||
|
||
Note: You can run the command with or without the generator specified. | ||
|
||
|
||
Answer the prompts: | ||
|
||
1. Project name (e.g. my-app) | ||
2. Service name (e.g. my-app-war) | ||
3. OpenShift Artifactory project (default: cc20) | ||
4. Maven pom file root (default: repository root) | ||
|
||
The generated files will appear in your .github/workflows and .jenkins directories. |
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,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Build the image | ||
podman build -t nr-pipeline-template . |
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,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,2 @@ | ||
coverage | ||
**/templates |
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,18 @@ | ||
# generator-nr-maven-build | ||
> Generate the CI workflow and NR Broker intention files needed Java/Tomcat Maven builds in GitHub | ||
## Installation | ||
|
||
First, install [Yeoman](http://yeoman.io), then install generator-nr-maven-build using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)). | ||
|
||
```bash | ||
npm install -g yo | ||
npm ci | ||
npm link | ||
``` | ||
|
||
Then generate the files: | ||
|
||
```bash | ||
yo nr-maven-build | ||
``` |
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,16 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const assert = require('yeoman-assert'); | ||
const helpers = require('yeoman-test'); | ||
|
||
describe('generator-build-deploy:app', () => { | ||
beforeAll(() => { | ||
return helpers | ||
.run(path.join(__dirname, '../generators/app')) | ||
.withPrompts({ someAnswer: true }); | ||
}); | ||
|
||
it('creates files', () => { | ||
assert.file(['dummyfile.txt']); | ||
}); | ||
}); |
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,71 @@ | ||
'use strict'; | ||
const Generator = require('yeoman-generator'); | ||
const chalk = require('chalk'); | ||
const yosay = require('yosay'); | ||
|
||
module.exports = class extends Generator { | ||
prompting() { | ||
this.log( | ||
yosay( | ||
'Welcome to the GitHub CI workflow and NR Broker intention file generator!' | ||
) | ||
); | ||
|
||
const prompts = [ | ||
{ | ||
type: 'input', | ||
name: 'projectName', | ||
message: 'What is your project name?', | ||
store: true | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'serviceName', | ||
message: 'what is your service name?', | ||
store: true | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'artifactoryProject', | ||
message: 'what is your Artifactory project?', | ||
default: "cc20", | ||
store: true | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'pomRoot', | ||
message: 'what is your Maven pom file root?', | ||
default: "./", | ||
store: true | ||
} | ||
]; | ||
|
||
return this.prompt(prompts).then(props => { | ||
this.props = props; | ||
}); | ||
} | ||
|
||
// Generate GitHub workflow and NR Broker intention files | ||
writing() { | ||
this.fs.copyTpl( | ||
this.templatePath('ci.yaml'), | ||
this.destinationPath('.github/workflows/ci.yaml'), | ||
{ projectName: this.props.projectName, serviceName: this.props.serviceName, artifactoryProject: this.props.artifactoryProject, | ||
pomRoot: this.props.pomRoot } | ||
); | ||
this.fs.copyTpl( | ||
this.templatePath('build-intention.json'), | ||
this.destinationPath('.github/workflows/build-intention.json'), | ||
{ projectName: this.props.projectName, serviceName: this.props.serviceName } | ||
); | ||
this.fs.copyTpl( | ||
this.templatePath('build-intention.sh'), | ||
this.destinationPath('.github/workflows/build-intention.sh') | ||
); | ||
this.fs.copyTpl( | ||
this.templatePath('deployment-intention.json'), | ||
this.destinationPath('.jenkins/deployment-intention.json'), | ||
{ projectName: this.props.projectName, serviceName: this.props.serviceName } | ||
); | ||
} | ||
}; |
26 changes: 26 additions & 0 deletions
26
generator-nr-maven-build/generators/app/templates/build-intention.json
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,26 @@ | ||
{ | ||
"event": { | ||
"provider": "github-action-build", | ||
"reason": "Job triggered", | ||
"url": "JOB_URL" | ||
}, | ||
"actions": [ | ||
{ | ||
"action": "package-build", | ||
"id": "build", | ||
"provision": [], | ||
"service": { | ||
"project": "<%= projectName %>", | ||
"name": "<%= serviceName %>", | ||
"environment": "tools" | ||
}, | ||
"package": { | ||
"version": "", | ||
"buildVersion": "" | ||
} | ||
} | ||
], | ||
"user": { | ||
"name": "github@internal" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
generator-nr-maven-build/generators/app/templates/build-intention.sh
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,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "===> Create Intention" | ||
# Create intention | ||
cat ./.github/workflows/build-intention.json | jq "\ | ||
.event.url=\"https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\" | \ | ||
(.actions[] | select(.id == \"build\") .service.project) |= \"${SERVICE_PROJECT}\" | \ | ||
(.actions[] | select(.id == \"build\") .service.name) |= \"${SERVICE_NAME}\" | \ | ||
(.actions[] | select(.id == \"build\") .package.version) |= \"${PROJECT_VERSION}\" | \ | ||
(.actions[] | select(.id == \"build\") .package.buildVersion) |= \"${GIT_COMMIT}\" \ | ||
" > intention.json |
Oops, something went wrong.