ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - alfiankan/crab-config-files-templating: Dynamic configuration file templating tool for kubernetes manifest or general configuration files
Dynamic configuration file templating tool for kubernetes manifest or general configuration files - alfiankan/crab-config-files-templating
Visit Site

GitHub - alfiankan/crab-config-files-templating: Dynamic configuration file templating tool for kubernetes manifest or general configuration files

GitHub - alfiankan/crab-config-files-templating: Dynamic configuration file templating tool for kubernetes manifest or general configuration files

Crab ๐Ÿฆ€

Dynamic configuration file templating tool for kubernetes manifest or general configuration files

codecov Go Reference Go Report Card Generate release-artifacts Mentioned in Awesome Go

How to install

Download according to your computer architecture at release page go to release page

OS Platform Status
Ubuntu, Debian amd64, arm64, 386 available
MacOS, Darwin amd64, arm64, 386 available
Windows amd64, arm64, 386 available

Extract using command like :

tar -xzf crab-cli-v0.1.0-darwin-amd64.tar.gz -C crab

Move to /usr/local/bin (Optional) :

cp crab/crab /usr/local/bin

Then check crab cli working properly :

Build From Source

  • clone this repository
  • make sure you have go version 18
  • run make build

How to use

basic command fromat :

  crab -f <fileinputpath> -r <keyvalue> -o <outputfilepath>

Flags :

Flag Description Required default
-f file input path location eg. ./manifest/nginx.yaml (accept any config file ext, .env, json, yml, yaml etc.) true -
-o write output file location eg. ./manifest/nginx-result.yaml false same as input file path (overwrite)
-r key value replacable true -
-q key value replacable with quotes false -
-v verbose process false false

Case 1 Standart replace

First add {{replacableName}} to your file :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: {{namespace}}
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: {{exposePort}}

crab cli will replace {{replacableName}} as the key, based on the example above :

  • {{namespace}}
  • {{exposePort}}

then run crab command :

  crab -f inputfile.yaml -r namespace=production -r exposePort=8081

yes you can override multiple key values โœ”๏ธ

write output to another file add -o flag:

  crab -f inputfile.yaml -r namespace=production -r exposePort=8081 -o result.yaml

to make verbose add -v flag:

  crab -f inputfile.yaml -r namespace=production -r exposePort=8081 -o result.yaml -v

verbose output :

[REPLACED] from namespace to production
[REPLACED] from exposePort to 8081
[DONE] Crab output result at result.yaml

the result will be :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: production
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: 8081

Click to watch the demo : asciicast

Youtube demo video :

Case 2 Quotes replace

sometimes your config file needs string quotes, (like for env vars or connection string):

  namespace="production"

template file example :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: {{namespace}}
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: {{exposePort}}

let's say we need a quote in the namespace :

  crab -f inputfile.yaml -q namespace=production -r exposePort=8081 -o result.yaml -v

yass you can simultaneously Replace multiple key values with quotes or not โœ”๏ธ

result will be :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: "production"
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: 8081

Sample Github Action

name: Demo deployment using crab

on:
  workflow_dispatch:

jobs:
  crab-manifest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: mock job
        run: pwd

  deploy-test:
    runs-on: ubuntu-latest
    needs: crab-manifest
    steps:
      - uses: actions/checkout@v3
      - name: install crab cli
        run: wget -c https://github.com/alfiankan/crab-config-files-templating/releases/download/v1.0.5/crab-v1.0.5-linux-amd64.tar.gz -O - | tar -xz crab
      - name: recreate deployment manifest on test
        run: |
          ./crab -f example/manifest/nginx.yaml \
          -r namespace=test \
          -r publishPort=8000 \
          -q portName=test-server \
          -o nginx-test.yaml \
          -v
      - name: view manifest
        run: cat nginx-test.yaml
                    
  
  deploy-production:
    runs-on: ubuntu-latest
    needs: crab-manifest
    steps:
      - uses: actions/checkout@v3
      - name: install crab cli
        run: wget -c https://github.com/alfiankan/crab-config-files-templating/releases/download/v1.0.5/crab-v1.0.5-linux-amd64.tar.gz -O - | tar -xz crab
      - name: recreate deployment manifest on production
        run: |
          ./crab -f example/manifest/nginx.yaml \
          -r namespace=production \
          -r publishPort=80 \
          -q portName=prod-server \
          -o nginx-prod.yaml \
          -v
      - name: view manifest
        run: cat nginx-prod.yaml

Related article

  • Replacing kubernetes manifest value dynamicly (coming soon on medium)

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory