Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jlenon7/templating
📖 Simple CLI to use inside pipelines to replace strings in any type of file
https://github.com/jlenon7/templating
Last synced: about 2 months ago
JSON representation
📖 Simple CLI to use inside pipelines to replace strings in any type of file
- Host: GitHub
- URL: https://github.com/jlenon7/templating
- Owner: jlenon7
- License: mit
- Created: 2021-10-28T02:56:49.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-03T18:47:43.000Z (almost 3 years ago)
- Last Synced: 2024-10-05T23:41:30.579Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 841 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Templating 📖
> Simple CLI to use inside pipelines to replace strings in any type of file
Templating is a simple alternative for `Helm template`, but can be used for `any type of file`.
## Installation
```bash
npm install -g @jlenon7/templating
```## Usage
### Commands
### Help
> See all commands and tips from templating.
```bash
templating --help
```### Generate
> Templating will always look for environment variables first and then set the local fields, and format
> any string that matches the regex {{ NAME }} in the templates folder path. **Please create your templates first,
> then run this command. [Click here to see an example](https://github.com/jlenon7/templating/tree/main/manifest)**.```bash
templating generate ./manifest/templates --set IMAGE_TAG=my-dockerhub-image:latest
```
> manifest/templates/config-map.yml
```yml
apiVersion: v1
kind: ConfigMap
metadata:
name: api
namespace: default
data:
HOST: "{{ HOST }}"
PORT: "{{ PORT }}"
NODE_ENV: "{{ NODE_ENV }}"```
> manifest/templates/deployment.yml
```yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
namespace: default
spec:
selector:
matchLabels:
run: api
replicas: 1
template:
metadata:
labels:
run: api
spec:
nodeSelector:
group: apps-public-vpc
containers:
- image: {{ IMAGE_TAG }}
imagePullPolicy: IfNotPresent
name: api
envFrom:
- configMapRef:
name: api
ports:
- containerPort: 80
protocol: TCP
name: http
resources:
limits:
memory: 500Mi
requests:
memory: 500Mi
```---
#### Using templating in a Gitlab CI pipeline
```yaml
services:
- docker:dindvariables:
IMAGE_LATEST: nickname-organization/your-image-name-here:latest
IMAGE_TAG: nickname-organization/your-image-name-here:$CI_COMMIT_SHAstages:
- test
- build
- deployVerify lint and run tests:
image: node:16.13.0
stage: test
services:
- redis:latest
- postgres:latest
variables:
POSTGRES_DB: "postgres"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "root"
DATABASE_URL_TESTING: "postgresql://postgres:root@postgres:5432/postgres?schema=public"
script:
- cp ./manifest/.env.ci .env.ci
- npm install --silent
- npm run lint:fix
- npm run test:ci
only:
- merge_requestsBuild and push image to Dockerhub:
image: docker:latest
stage: build
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker pull $IMAGE_LATEST || true
- docker build --cache-from $IMAGE_LATEST -t $IMAGE_TAG -t $IMAGE_LATEST .
- docker push $IMAGE_TAG
- docker push $IMAGE_LATEST
only:
- mainDeploy image to K8S Cluster:
image: jlenon7/gitlab-deploy:latest
stage: deploy
script:
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set region $AWS_DEFAULT_REGION
- aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name eks-$AWS_DEFAULT_REGION-production
- templating generate ./manifest/templates --set IMAGE_TAG=$IMAGE_TAG
- kubectl apply -f ./manifest/config-map.yml -f ./manifest/deployment.yml
needs: ["Build and push image to Dockerhub"]
only:
- main
```---
Made with 🖤 by [jlenon7](https://github.com/jlenon7) :wave: