Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsonnet 이란? #164

Open
occidere opened this issue Sep 11, 2021 · 0 comments
Open

Jsonnet 이란? #164

occidere opened this issue Sep 11, 2021 · 0 comments
Assignees
Labels

Comments

@occidere
Copy link
Owner

occidere commented Sep 11, 2021

Jsonnet 이란?

JSON 을 확장한 템플릿 언어

  • 오픈소스 (Apache 2.0)
  • JSON 과 문법이 유사
  • Reformatter, Linter 지원
  • Editor & IDE 지원
  • original implementationgo 언어 기반 implementation 이 있음
  • JSON 과 Sonnet 의 합성어로 제이소넷으로 발음함
  • Google 의 공식 제품은 아니며, 코드 소유권만 google 에게 있음

image

1. 객체지향적인 방식으로 중복 제거

input.jsonnet

{
  corp1: {
    name: "NAVER",
    welcome: "Welcome to " + self.name + " Corp",
  },
  corp2: self.corp1 { name: "COUPANG" },
}

output.json

{
  "corp1": {
    "name": "NAVER",
    "welcome": "Welcome to NAVER Corp"
  },
  "corp2": {
    "name": "COUPANG",
    "welcome": "Welcome to COUPANG Corp"
  }
}

2. 함수 사용하기

input.jsonnet

local Corp(name='NAVER') = {
  name: name,
  welcome: 'Welcome to ' + name + ' Corp',
};

{
  corp1: Corp(),
  corp2: Corp('COUPANG'),
}

output.json

{
  "corp1": {
    "name": "NAVER",
    "welcome": "Welcome to NAVER Corp"
  },
  "corp2": {
    "name": "COUPANG",
    "welcome": "Welcome to COUPANG Corp"
  }
}

3. 기존 어플리케이션 및 커스텀 어플리케이션과 통합

input.jsonnet

local application = 'my-app';
local module = 'uwsgi_module';
local dir = '/var/www';
local permission = 644;

{
  'uwsgi.ini': std.manifestIni({
    sections: {
      uwsgi: {
        module: module,
        pythonpath: dir,
        socket: dir + '/uwsgi.sock',
        'chmod-socket': permission,
        callable: application,
        logto: '/var/log/uwsgi/uwsgi.log',
      },
    },
  }),

  'init.sh': |||
    #!/usr/bin/env bash
    mkdir -p %(dir)s
    touch %(dir)s/initialized
    chmod %(perm)d %(dir)s/initialized
  ||| % {dir: dir, perm: permission},

  'cassandra.conf': std.manifestYamlDoc({
    cluster_name: application,
    seed_provider: [
      {
        class_name: 'SimpleSeedProvider',
        parameters: [{ seeds: '127.0.0.1' }],
      },
    ],
  }),
}

uwsgi.ini

[uwsgi]
callable = my-app
chmod-socket = 644
logto = /var/log/uwsgi/uwsgi.log
module = uwsgi_module
pythonpath = /var/www
socket = /var/www/uwsgi.sock

init.sh

#!/usr/bin/env bash
mkdir -p /var/www
touch /var/www/initialized
chmod 644 /var/www/initialized

cassandra.conf

"cluster_name": "my-app"
"seed_provider":
- "class_name": "SimpleSeedProvider"
  "parameters":
  - "seeds": "127.0.0.1"

참고

@occidere occidere self-assigned this Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant