D2 1. Getting Started - swkim0128/PARA GitHub Wiki
Install
Hello World
Shape
Connections
Connections must reference a shape's key, not its label.
Containers
The recommended way to install is to run our install script, which will figure out the best way to install based on your machine. E.g. if D2 is available through a package manager installed, it will use that package manager.
๊ถ์ฅํ๋ ์ค์น ๋ฐฉ๋ฒ์ ์ฐ๋ฆฌ์ ์ค์น ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๋ ๊ฒ์ ๋๋ค. ์ด ์คํฌ๋ฆฝํธ๋ ๋น์ ์ ์ปดํจํฐ์ ๋ฐ๋ผ ๊ฐ์ฅ ์ ํฉํ ์ค์น ๋ฐฉ๋ฒ์ ์ฐพ์์ค๋๋ค. ์๋ฅผ ๋ค์ด, D2๊ฐ ํจํค์ง ๋งค๋์ ๋ฅผ ํตํด ์ค์น ๊ฐ๋ฅํ ๊ฒฝ์ฐ์๋ ํด๋น ํจํค์ง ๋งค๋์ ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
# With --dry-run the install script will print the commands it will use
# to install without actually installing so you know what it's going to do.
curl -fsSL https://d2lang.com/install.sh | sh -s -- --dry-run
# If things look good, install for real.
curl -fsSL https://d2lang.com/install.sh | sh -s --Follow the instructions, if any. Test your installation was successful by running d2 version.
If you want to uninstall:
curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstallAlternatively, you can install from source:
๋์ ์์ค์์ ์ค์นํ ์ ์์ต๋๋ค:
go install oss.terrastruct.com/d2x -> y: hello world
You can declare shapes like so:
imAShape
im_a_shape
im a shape
i'm a shape
# notice that one-hyphen is not a connection
# whereas, `a--shape` would be a connection
a-shape
You can also use semicolons to define multiple shapes on the same line:
ํ๋์ ์ค์ ์ฌ๋ฌ ๊ฐ์ ๋ํ์ ์ ์ํ๋ ค๋ฉด ์ธ๋ฏธ์ฝ๋ก ์ ์ฌ์ฉํ ์ ์์ต๋๋ค:
1SQLite; Cassandra
By default, a shape's label is the same as the shape's key. But if you want it to be different, assign a new label like so:
๊ธฐ๋ณธ์ ์ผ๋ก ๋ํ์ ๋ผ๋ฒจ์ ๋ํ์ ํค์ ๊ฐ์ต๋๋ค. ํ์ง๋ง ๋ค๋ฅธ ๋ผ๋ฒจ์ ์ํ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์ ๋ผ๋ฒจ์ ํ ๋นํ์ธ์:
1pg: PostgreSQL
By default, a shape's type is rectangle. To specify otherwise, provide the field shape:
๊ธฐ๋ณธ์ ์ผ๋ก ๋ํ์ ์ ํ์ ์ฌ๊ฐํ์
๋๋ค. ๋ค๋ฅธ ์ ํ์ ์ง์ ํ๋ ค๋ฉด shape ํ๋๋ฅผ ์ ๊ณตํ์ญ์์ค:
Cloud: my cloud
Cloud.shape: cloud
pg: PostgreSQL
Cloud: my cloud
Cloud.shape: cloud
SQLite; Cassandra
Important
SHAPE CATALOGrectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloudSpecial shape types (more on these next):textcodeclasssql_tableimagesequence_diagram
Connections define relationships between shapes.
์ฐ๊ฒฐ์ ๋ํ ๊ฐ์ ๊ด๊ณ๋ฅผ ์ ์ํฉ๋๋ค.
Hyphens/arrows in between shapes define a connection.
๋ํ ์ฌ์ด์ ํ์ดํ/ํ์ดํ๋ ์ฐ๊ฒฐ์ ์ ์ํฉ๋๋ค.
Write Replica Canada <-> Write Replica Australia
Read Replica <- Master
Write Replica -> Master
Read Replica 1 -- Read Replica 2
If you reference an undeclared shape in a connection, it's created (as shown in the hello world example).
์ฐ๊ฒฐ์์ ์ ์ธ๋์ง ์์ ๋ํ์ ์ฐธ์กฐํ๋ฉด, hello world ์์ ์์ ๋ณด์ฌ์ง๋ฏ์ด, ๋ํ์ด ์์ฑ๋ฉ๋๋ค.
Important
INFOThere are 4 valid ways to define a connection:---><-<->
Read Replica 1 -- Read Replica 2: Kept in sync
์ฐ๊ฒฐ์ ๋ชจ์์ ๋ผ๋ฒจ์ด ์๋ ํค๋ฅผ ์ฐธ์กฐํด์ผํฉ๋๋ค.
be: Backend
fe: Frontend
# This would create new shapes
Backend -> Frontend
# This would define a connection over existing labels
be -> fe
Write Replica Canada <-> Write Replica Australia
Read Replica <- Master
x -- y
super long shape id here --\
-> super long shape id even longer here
Repeated connections do not override existing connections. They declare new ones.
๋ฐ๋ณต ์ฐ๊ฒฐ์ ๊ธฐ์กด ์ฐ๊ฒฐ์ ๋ฎ์ด์ฐ์ง ์์ต๋๋ค. ์๋ก์ด ์ฐ๊ฒฐ์ ์ ์ธํฉ๋๋ค.
Database -> S3: backup
Database -> S3
Database -> S3: backup
For readability, it may look more natural to define multiple connection in a single line.
๊ฐ๋ ์ฑ์ ์ํด ์ฌ๋ฌ ์ฐ๊ฒฐ์ ํ ์ค์ ์ ์ํ๋ ๊ฒ์ด ๋ ์์ฐ์ค๋ฌ์ธ ์ ์์ต๋๋ค.
# The label applies to each connection in the chain.
High Mem Instance -> EC2 <- High CPU Instance: Hosted By
Stage One -> Stage Two -> Stage Three -> Stage Four
Stage Four -> Stage One: repeat
To override the default arrowhead shape or give a label next to arrowheads, define a special shape on connections named source-arrowhead and/or target-arrowhead.
๊ธฐ๋ณธ ํ์ดํ ๋จธ๋ฆฌ ๋ชจ์์ ๋ฎ์ด์ฐ๊ฑฐ๋ ํ์ดํ ๋จธ๋ฆฌ ์์ ๋ ์ด๋ธ์ ์ง์ ํ๋ ค๋ฉด, ์ฐ๊ฒฐ์ ๋ํ ํน์ํ ๋ชจ์์ source-arrowhead ๋ฐ/๋๋ target-arrowhead๋ก ์ ์ํ์ญ์์ค.
a: The best way to avoid responsibility is to say, "I've got responsibilities"
b: Whether weary or unweary, O man, do not rest
c: I still maintain the point that designing a monolithic kernel in 1991 is a
a -> b: To err is human, to moo bovine {
source-arrowhead: 1
target-arrowhead: * {
shape: diamond
}
}
b <-> c: "Reality is just a crutch for people who can't handle science fiction" {
source-arrowhead.label: 1
target-arrowhead: * {
shape: diamond
style.filled: true
}
}
d: A black cat crossing your path signifies that the animal is going somewhere
d -> a -> c
Important
ARROWHEAD OPTIONStriangle (default)arrow (like triangle but pointier)diamondCan be further styled as style.filled: true.circleCan be further styled as style.filled: true.cf-one, cf-one-required (cf stands for crows foot)cf-many, cf-many-required
server
# Declares a shape inside of another shape
server.process
# Can declare the container and child in same line
im a parent.im a child
# Since connections can also declare keys, this works too
apartment.Bedroom.Bathroom -> office.Spare Room.Bathroom: Portal
You can avoid repeating containers by creating nested maps.
์ค์ฒฉ๋ ๋งต์ ๋ง๋ค์ด ๋ฐ๋ณต์ ์ธ ์ปจํ ์ด๋๋ฅผ ํผํ ์ ์์ต๋๋ค.
clouds: {
aws: {
load_balancer -> api
api -> db
}
gcloud: {
auth -> db
}
gcloud -> aws
}
There are two ways define container labels.
์ปจํ ์ด๋ ๋ผ๋ฒจ์ ์ ์ํ๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
gcloud: Google Cloud {
...
}
gcloud: {
label: Google Cloud
...
}
clouds: {
aws: AWS {
load_balancer -> api
api -> db
}
gcloud: Google Cloud {
auth -> db
}
gcloud -> aws
}
users -> clouds.aws.load_balancer
users -> clouds.gcloud.auth
ci.deploys -> clouds
Sometimes you want to reference something outside of the container from within. The underscore (_) refers to parent.
๊ฐ๋์ ์ปจํ
์ด๋ ์ธ๋ถ์ ๊ฒ์ ์ฐธ์กฐํ๊ณ ์ถ์ ๋๊ฐ ์์ต๋๋ค. ๋ฐ์ค(_)์ ๋ถ๋ชจ๋ฅผ ์ฐธ์กฐํฉ๋๋ค.
christmas: {
presents
}
birthdays: {
presents
_.christmas.presents -> presents: regift
_.christmas.style.fill: "\#ACE1AF"
}