Skip to content

Commit

Permalink
Merge branch 'main' into feature/private-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenan Dervisevic authored Oct 3, 2023
2 parents a3a28a4 + 70cd5ab commit d02de97
Show file tree
Hide file tree
Showing 33 changed files with 4,121 additions and 116 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/onbranch.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build on branch

on:
push:
branches-ignore:
- "main"
push:
branches-ignore:
- "main"

jobs:
cli:
Expand All @@ -23,4 +23,4 @@ jobs:
env:
INITIUM_APP_NAME: initium-cli
INITIUM_REGISTRY_USER: ${{ github.actor }}
INITIUM_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
INITIUM_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/onmain.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Deploy on main

on:
on:
push:
branches:
- main
Expand All @@ -21,4 +21,4 @@ jobs:
env:
INITIUM_APP_NAME: initium-cli
INITIUM_REGISTRY_USER: ${{ github.actor }}
INITIUM_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
INITIUM_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
71 changes: 57 additions & 14 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,69 @@ on:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
permissions:
pull-requests: write
contents: write
id-token: write
runs-on: ubuntu-latest
steps:
- uses: tibdex/[email protected]
id: get_installation_token
## Build a release based on the release-please-config.json file
- uses: google-github-actions/release-please-action@v3
id: release
with:
app_id: ${{ secrets.RELEASE_PLEASE_APP_ID }}
installation_id: ${{ secrets.RELEASE_PLEASE_APP_INSTALLATION_ID }}
private_key: ${{ secrets.RELEASE_PLEASE_APP_PRIVATE_KEY }}
command: manifest

- uses: google-github-actions/release-please-action@v3
## Build go binary and add it to the release
- uses: actions/checkout@v4
with:
fetch-depth: 0
if: ${{ steps.release.outputs.release_created }}

- uses: actions/setup-go@v4
with:
go-version: stable
if: ${{ steps.release.outputs.release_created }}

- name: Build go binaries
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ steps.release.outputs.release_created }}

## Publish the release to npm
- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}

- name: Get commit author
id: commit_author
run: |
author=$(gh pr list --search ${{ github.sha }} --state merged --json mergedBy --jq '.[0].mergedBy.login')
echo "author=${author}" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token }}
if: ${{ steps.release.outputs.release_created }}

- uses: actions/setup-node@v3
# This sets up the .npmrc file for publishing to npm
with:
release-type: go
token: ${{ steps.get_installation_token.outputs.token }}
bump-minor-pre-major: true
package-name: release-please-action
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
if: ${{ steps.release.outputs.release_created }}

- name: Run npm publish
shell: bash
run: |
cd npm
./publish.sh
env:
NPM_TOKEN: ${{ secrets[format('NPM_TOKEN_{0}', steps.commit_author.outputs.author)] || secrets.NPM_TOKEN }}
OPTIC_TOKEN: ${{ secrets[format('OPTIC_TOKEN_{0}', steps.commit_author.outputs.author)] || secrets.OPTIC_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
35 changes: 0 additions & 35 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Dockerfile.initium
initium_onmain.yaml
initium_onbranch.yaml
dist/

node_modules
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ before:
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- binary: initium
env:
- CGO_ENABLED=0
goos:
- linux
Expand Down
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.6.0"
}
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# Changelog

## [0.6.0](https://github.com/nearform/initium-cli/compare/v0.5.0...v0.6.0) (2023-10-03)


### Features

* Come up with a standard to pass configuration to the deployed application ([#115](https://github.com/nearform/initium-cli/issues/115)) ([f1b3c2b](https://github.com/nearform/initium-cli/commit/f1b3c2baf4f47e19d59a7089b790c02e9c50b25c))
* unify all release steps in a single pipeline ([#113](https://github.com/nearform/initium-cli/issues/113)) ([93f4be9](https://github.com/nearform/initium-cli/commit/93f4be9305056e7c67f6cadeca1f7809a17efb88))


### Bug Fixes

* add annotations to ensure new docker image is downloaded ([#117](https://github.com/nearform/initium-cli/issues/117)) ([2627252](https://github.com/nearform/initium-cli/commit/262725205322c44870eccfbe351ff2ff448f1d94))

## [0.5.0](https://github.com/nearform/initium-cli/compare/v0.4.0...v0.5.0) (2023-09-21)


### Features

* allow release please to publish to npm ([5129767](https://github.com/nearform/initium-cli/commit/51297674339ff204afc71d6f6ee2ed38027fa9fa))

## [0.4.0](https://github.com/nearform/initium-cli/compare/v0.3.0...v0.4.0) (2023-09-21)


### Features

* change released binary name to initium ([#107](https://github.com/nearform/initium-cli/issues/107)) ([798a813](https://github.com/nearform/initium-cli/commit/798a813687a4c5356016b02dbfc292a65a5f772d))


### Bug Fixes

* execute publish steps only on release ([#110](https://github.com/nearform/initium-cli/issues/110)) ([abb4439](https://github.com/nearform/initium-cli/commit/abb4439d6638fca609316fa6b0fd621135cf75e6))
* release-please action failing for missing `)` ([#109](https://github.com/nearform/initium-cli/issues/109)) ([b12c919](https://github.com/nearform/initium-cli/commit/b12c919c241fcedb2594979cff666d63176a080d))

## [0.3.0](https://github.com/nearform/initium-cli/compare/v0.2.0...v0.3.0) (2023-09-04)


### Features

* get smarter at detecting app name ([#87](https://github.com/nearform/initium-cli/issues/87)) ([4fbe947](https://github.com/nearform/initium-cli/commit/4fbe947e9478d9452eac29495339cbee8ef5ea67))


### Bug Fixes

* avoid running closed PR action immediately after reopen ([#98](https://github.com/nearform/initium-cli/issues/98)) ([107b505](https://github.com/nearform/initium-cli/commit/107b505c943bf3c487d04c720f0ff0ac8e6576da))
* the init github command does not require the shared flags ([#93](https://github.com/nearform/initium-cli/issues/93)) ([6c9a32c](https://github.com/nearform/initium-cli/commit/6c9a32cfc682b5a081a84eb93c2d3550730720e8))

## [0.2.0](https://github.com/nearform/initium-cli/compare/v0.1.0...v0.2.0) (2023-08-18)


Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ A single static binary that can run on any CI to build your code and deploy it i

All with a nice development workflow in mind like ephemeral environment for your PRs.

### Running the CLI

The CLI is currently published on [NPM](https://www.npmjs.com/package/initium). You can run it using

```
npx initium
```

That will install the Initium CLI in your folder's `node_modules`.

We recommend you not to try installing the CLI globally if you don't use a Node.js version manager (like `nvm`), as you can run into permission errors.

### Pre-requisites

1. GoLang
Expand Down Expand Up @@ -47,3 +59,26 @@ export INITIUM_CLUSTER_ENDPOINT=$(kubectl config view -o jsonpath='{.clusters[?(
export INITIUM_CLUSTER_TOKEN=$(kubectl get secrets initium-cli-token -o jsonpath="{.data.token}" | base64 -d)
export INITIUM_CLUSTER_CA_CERT=$(kubectl get secrets initium-cli-token -o jsonpath="{.data.ca\.crt}" | base64 -d)
```

### Supported Application Runtimes

Following we have a matrix related to which application runtime our CLI is currently compatible with. For each one of them a Dockerfile template is being used in order to provide an easy way to build and deploy the application to a Kubernetes cluster.

| Application Runtimes | Supported |
|----------------------|:------------------:|
| [Nodejs](https://github.com/nearform/initium-cli/blob/main/assets/docker/Dockerfile.node.tmpl) | :white_check_mark: |
| [GoLang](https://github.com/nearform/initium-cli/blob/main/assets/docker/Dockerfile.go.tmpl) | :white_check_mark: |
| Python | Coming Soon |
| More will be added...| |


### CI Integrations

The matrix below gives an overview of the integration status of our CLI with CI platforms. CLI is able to create automatically `build` and `deploy` pipelines in order to enable CICD process for the application it is used with. Related template files are being used to cover different process steps.

| CI Systems | Supported |
|----------------------|:------------------:|
| [GitHub Actions](https://github.com/nearform/initium-cli/tree/main/assets/github) | :white_check_mark: |
| Gitlab CI | Coming Soon |
| Azure Devops | Coming Soon |
| More will be added...| |
19 changes: 13 additions & 6 deletions assets/github/onbranch.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,40 @@ on:

jobs:
on_pr:
if: github.event.action != 'closed'
concurrency: {{ `${{ github.head_ref }}` }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: {{ `${{ github.head_ref }}` }}

- name: delete application
if: github.event.action == 'closed'
- name: build and deploy application
uses: docker://ghcr.io/nearform/initium-cli:latest
with:
args: onbranch --clean
args: onbranch
env:
INITIUM_REGISTRY_USER: {{ `${{ github.actor }}` }}
INITIUM_REGISTRY_PASSWORD: {{ `${{ secrets.GITHUB_TOKEN }}` }}
INITIUM_CLUSTER_ENDPOINT: {{ `${{ secrets.CLUSTER_ENDPOINT }}` }}
INITIUM_CLUSTER_TOKEN: {{ `${{ secrets.CLUSTER_TOKEN }}` }}
INITIUM_CLUSTER_CA_CERT: {{ `${{ secrets.CLUSTER_CA_CERT }}` }}

- name: build and deploy application
if: github.event.action != 'closed'
closed_pr:
if: github.event.action == 'closed'
concurrency: {{ `${{ github.head_ref }}` }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: delete application
uses: docker://ghcr.io/nearform/initium-cli:latest
with:
args: onbranch
args: onbranch --clean --branch-name {{ `${{ github.head_ref }}` }}
env:
INITIUM_REGISTRY_USER: {{ `${{ github.actor }}` }}
INITIUM_REGISTRY_PASSWORD: {{ `${{ secrets.GITHUB_TOKEN }}` }}
INITIUM_CLUSTER_ENDPOINT: {{ `${{ secrets.CLUSTER_ENDPOINT }}` }}
INITIUM_CLUSTER_TOKEN: {{ `${{ secrets.CLUSTER_TOKEN }}` }}
INITIUM_CLUSTER_CA_CERT: {{ `${{ secrets.CLUSTER_CA_CERT }}` }}

2 changes: 1 addition & 1 deletion assets/github/onmain.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: build and deploy on {{ .DefaultBranch }}
uses: docker://ghcr.io/nearform/initium-cli:latest
Expand Down
4 changes: 4 additions & 0 deletions example/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MOCK1="value1"
MOCK2="value2"
MOCK3:"value3"
MOCK4 "value4"
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ go 1.20

require (
github.com/charmbracelet/log v0.2.2
github.com/docker/docker v23.0.1+incompatible
github.com/docker/docker v23.0.3+incompatible
github.com/go-git/go-git/v5 v5.7.0
github.com/moby/term v0.0.0-20221205130635-1aeaba878587
github.com/urfave/cli/v2 v2.25.0
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.0.3
k8s.io/api v0.27.1
k8s.io/apimachinery v0.27.1
k8s.io/client-go v0.27.1
Expand All @@ -28,7 +29,7 @@ require (
github.com/containerd/containerd v1.7.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
Expand Down Expand Up @@ -69,7 +70,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/opencontainers/runc v1.1.4 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
Loading

0 comments on commit d02de97

Please sign in to comment.