opencode / packages /web /src /content /docs /ko /gitlab.mdx
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
0dbc9de verified
Raw
History Blame Contribute Delete
6.98 kB
---
title: GitLab
description: GitLab ์ด์Šˆ์™€ merge request์—์„œ OpenCode๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.
---
OpenCode๋Š” GitLab CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๋˜๋Š” GitLab Duo๋ฅผ ํ†ตํ•ด GitLab ์›Œํฌํ”Œ๋กœ์— ํ†ตํ•ฉ๋ฉ๋‹ˆ๋‹ค.
๋‘ ๊ฒฝ์šฐ ๋ชจ๋‘ OpenCode๋Š” GitLab runner์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
---
## GitLab CI
OpenCode๋Š” ์ผ๋ฐ˜ GitLab ํŒŒ์ดํ”„๋ผ์ธ์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. [CI component](https://docs.gitlab.com/ee/ci/components/)๋กœ ํŒŒ์ดํ”„๋ผ์ธ์— ํ†ตํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์—ฌ๊ธฐ์„œ๋Š” OpenCode์šฉ ์ปค๋ฎค๋‹ˆํ‹ฐ ์ œ์ž‘ CI/CD component์ธ [nagyv/gitlab-opencode](https://gitlab.com/nagyv/gitlab-opencode)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
---
### ๊ธฐ๋Šฅ
- **job๋ณ„ custom config ์‚ฌ์šฉ**: custom config ๋””๋ ‰ํ„ฐ๋ฆฌ(์˜ˆ: `./config/#custom-directory`)๋ฅผ ์‚ฌ์šฉํ•ด OpenCode๋ฅผ ๊ฐ ์‹คํ–‰ ๋‹จ์œ„๋กœ ์„ค์ •ํ•˜๊ณ  ๊ธฐ๋Šฅ์„ ์ผœ๊ฑฐ๋‚˜ ๋Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
- **์ตœ์†Œ ์„ค์ •**: CI component๊ฐ€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ OpenCode๋ฅผ ์„ค์ •ํ•˜๋ฏ€๋กœ OpenCode config์™€ ์ดˆ๊ธฐ prompt๋งŒ ๋งŒ๋“ค๋ฉด ๋ฉ๋‹ˆ๋‹ค.
- **์œ ์—ฐํ•จ**: CI component๋Š” ๋™์ž‘์„ ์‚ฌ์šฉ์žํ™”ํ•  ์ˆ˜ ์žˆ๋„๋ก ์—ฌ๋Ÿฌ ์ž…๋ ฅ๊ฐ’์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
---
### Setup
1. OpenCode ์ธ์ฆ JSON์„ **Settings** > **CI/CD** > **Variables** ์•„๋ž˜์˜ File ํƒ€์ž… CI ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ ์ €์žฅํ•˜์„ธ์š”. ๋ฐ˜๋“œ์‹œ "Masked and hidden"์œผ๋กœ ํ‘œ์‹œํ•˜์„ธ์š”.
2. ์•„๋ž˜ ๋‚ด์šฉ์„ `.gitlab-ci.yml` ํŒŒ์ผ์— ์ถ”๊ฐ€ํ•˜์„ธ์š”.
```yaml title=".gitlab-ci.yml"
include:
- component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2
inputs:
config_dir: ${CI_PROJECT_DIR}/opencode-config
auth_json: $OPENCODE_AUTH_JSON # The variable name for your OpenCode authentication JSON
command: optional-custom-command
message: "Your prompt here"
```
๋” ๋งŽ์€ ์ž…๋ ฅ๊ฐ’๊ณผ ์‚ฌ์šฉ ์‚ฌ๋ก€๋Š” ์ด component์˜ [docs](https://gitlab.com/explore/catalog/nagyv/gitlab-opencode)์—์„œ ํ™•์ธํ•˜์„ธ์š”.
---
## GitLab Duo
OpenCode๋Š” GitLab ์›Œํฌํ”Œ๋กœ์— ํ†ตํ•ฉ๋ฉ๋‹ˆ๋‹ค.
๋Œ“๊ธ€์—์„œ `@opencode`๋ฅผ ๋ฉ˜์…˜ํ•˜๋ฉด OpenCode๊ฐ€ GitLab CI ํŒŒ์ดํ”„๋ผ์ธ ์•ˆ์—์„œ ์ž‘์—…์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
---
### ๊ธฐ๋Šฅ
- **์ด์Šˆ ๋ถ„๋ฅ˜**: OpenCode์— ์ด์Šˆ๋ฅผ ์‚ดํŽด๋ณด๊ณ  ์„ค๋ช…ํ•ด ๋‹ฌ๋ผ๊ณ  ์š”์ฒญํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
- **์ˆ˜์ • ๋ฐ ๊ตฌํ˜„**: OpenCode์— ์ด์Šˆ๋ฅผ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด ๋‹ฌ๋ผ๊ณ  ์š”์ฒญํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
OpenCode๋Š” ์ƒˆ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค๊ณ  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ๋‹ด๊ธด merge request๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
- **๋ณด์•ˆ**: OpenCode๋Š” GitLab runner์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
---
### Setup
OpenCode๋Š” GitLab CI/CD ํŒŒ์ดํ”„๋ผ์ธ์—์„œ ์‹คํ–‰๋˜๋ฉฐ, ์„ค์ •์— ํ•„์š”ํ•œ ํ•ญ๋ชฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
:::tip
[์ตœ์‹  ์•ˆ๋‚ด๋Š” **GitLab docs**](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/)๋ฅผ ํ™•์ธํ•˜์„ธ์š”.
:::
1. GitLab ํ™˜๊ฒฝ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
2. CI/CD๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
3. AI model provider API ํ‚ค๋ฅผ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.
4. ์„œ๋น„์Šค ๊ณ„์ •์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
5. CI/CD ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
6. flow config ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
<details>
<summary>Flow configuration</summary>
```yaml
image: node:22-slim
commands:
- echo "Installing opencode"
- npm install --global opencode-ai
- echo "Installing glab"
- export GITLAB_TOKEN=$GITLAB_TOKEN_OPENCODE
- apt-get update --quiet && apt-get install --yes curl wget gpg git && rm --recursive --force /var/lib/apt/lists/*
- curl --silent --show-error --location "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | bash
- apt-get install --yes glab
- echo "Configuring glab"
- echo $GITLAB_HOST
- echo "Creating OpenCode auth configuration"
- mkdir --parents ~/.local/share/opencode
- |
cat > ~/.local/share/opencode/auth.json << EOF
{
"anthropic": {
"type": "api",
"key": "$ANTHROPIC_API_KEY"
}
}
EOF
- echo "Configuring git"
- git config --global user.email "opencode@gitlab.com"
- git config --global user.name "OpenCode"
- echo "Testing glab"
- glab issue list
- echo "Running OpenCode"
- |
opencode run "
You are an AI assistant helping with GitLab operations.
Context: $AI_FLOW_CONTEXT
Task: $AI_FLOW_INPUT
Event: $AI_FLOW_EVENT
Please execute the requested task using the available GitLab tools.
Be thorough in your analysis and provide clear explanations.
<important>
Please use the glab CLI to access data from GitLab. The glab CLI has already been authenticated. You can run the corresponding commands.
If you are asked to summarize an MR or issue or asked to provide more information then please post back a note to the MR/Issue so that the user can see it.
You don't need to commit or push up changes, those will be done automatically based on the file changes you make.
</important>
"
- git checkout --branch $CI_WORKLOAD_REF origin/$CI_WORKLOAD_REF
- echo "Checking for git changes and pushing if any exist"
- |
if ! git diff --quiet || ! git diff --cached --quiet || [ --not --zero "$(git ls-files --others --exclude-standard)" ]; then
echo "Git changes detected, adding and pushing..."
git add .
if git diff --cached --quiet; then
echo "No staged changes to commit"
else
echo "Committing changes to branch: $CI_WORKLOAD_REF"
git commit --message "Codex changes"
echo "Pushing changes up to $CI_WORKLOAD_REF"
git push https://gitlab-ci-token:$GITLAB_TOKEN@$GITLAB_HOST/gl-demo-ultimate-dev-ai-epic-17570/test-java-project.git $CI_WORKLOAD_REF
echo "Changes successfully pushed"
fi
else
echo "No git changes detected, skipping push"
fi
variables:
- ANTHROPIC_API_KEY
- GITLAB_TOKEN_OPENCODE
- GITLAB_HOST
```
</details>
[GitLab CLI agents docs](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/)์—์„œ ์ž์„ธํ•œ ์•ˆ๋‚ด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
---
### ์˜ˆ์ œ
๋‹ค์Œ์€ GitLab์—์„œ OpenCode๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ช‡ ๊ฐ€์ง€ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.
:::tip
`@opencode` ๋Œ€์‹  ๋‹ค๋ฅธ trigger phrase๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
:::
- **์ด์Šˆ ์„ค๋ช…**
GitLab ์ด์Šˆ์— ์•„๋ž˜ ๋Œ“๊ธ€์„ ๋‚จ๊ธฐ์„ธ์š”.
```
@opencode explain this issue
```
OpenCode๊ฐ€ ์ด์Šˆ๋ฅผ ์ฝ๊ณ  ๋ช…ํ™•ํ•œ ์„ค๋ช…์œผ๋กœ ๋‹ต๋ณ€ํ•ฉ๋‹ˆ๋‹ค.
- **์ด์Šˆ ํ•ด๊ฒฐ**
GitLab ์ด์Šˆ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์š”์ฒญํ•˜์„ธ์š”.
```
@opencode fix this
```
OpenCode๊ฐ€ ์ƒˆ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค๊ณ  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๊ตฌํ˜„ํ•œ ๋’ค, ํ•ด๋‹น ๋ณ€๊ฒฝ ์‚ฌํ•ญ์œผ๋กœ merge request๋ฅผ ์—ฝ๋‹ˆ๋‹ค.
- **๋จธ์ง€ ๋ฆฌํ€˜์ŠคํŠธ ๊ฒ€ํ† **
GitLab merge request์— ์•„๋ž˜ ๋Œ“๊ธ€์„ ๋‚จ๊ธฐ์„ธ์š”.
```
@opencode review this merge request
```
OpenCode๊ฐ€ merge request๋ฅผ ๊ฒ€ํ† ํ•˜๊ณ  ํ”ผ๋“œ๋ฐฑ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.