| --- |
| title: GitLab |
| description: GitLab ์ด์์ merge request์์ OpenCode๋ฅผ ์ฌ์ฉํ์ธ์. |
| --- |
| |
| OpenCode๋ GitLab CI/CD ํ์ดํ๋ผ์ธ ๋๋ GitLab Duo๋ฅผ ํตํด GitLab ์ํฌํ๋ก์ ํตํฉ๋ฉ๋๋ค. |
|
|
| ๋ ๊ฒฝ์ฐ ๋ชจ๋ OpenCode๋ GitLab runner์์ ์คํ๋ฉ๋๋ค. |
|
|
| --- |
| |
| |
|
|
| 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๋ ๋์์ ์ฌ์ฉ์ํํ ์ ์๋๋ก ์ฌ๋ฌ ์
๋ ฅ๊ฐ์ ์ง์ํฉ๋๋ค. |
|
|
| --- |
| |
| |
|
|
| 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 |
| command: optional-custom-command |
| message: "Your prompt here" |
| ``` |
|
|
| ๋ ๋ง์ ์
๋ ฅ๊ฐ๊ณผ ์ฌ์ฉ ์ฌ๋ก๋ ์ด component์ [docs](https://gitlab.com/explore/catalog/nagyv/gitlab-opencode)์์ ํ์ธํ์ธ์. |
|
|
| --- |
| |
| |
|
|
| OpenCode๋ GitLab ์ํฌํ๋ก์ ํตํฉ๋ฉ๋๋ค. |
| ๋๊ธ์์ `@opencode`๋ฅผ ๋ฉ์
ํ๋ฉด OpenCode๊ฐ GitLab CI ํ์ดํ๋ผ์ธ ์์์ ์์
์ ์คํํฉ๋๋ค. |
|
|
| --- |
| |
| |
|
|
| - **์ด์ ๋ถ๋ฅ**: OpenCode์ ์ด์๋ฅผ ์ดํด๋ณด๊ณ ์ค๋ช
ํด ๋ฌ๋ผ๊ณ ์์ฒญํ ์ ์์ต๋๋ค. |
| - **์์ ๋ฐ ๊ตฌํ**: OpenCode์ ์ด์๋ฅผ ์์ ํ๊ฑฐ๋ ๊ธฐ๋ฅ์ ๊ตฌํํด ๋ฌ๋ผ๊ณ ์์ฒญํ ์ ์์ต๋๋ค. |
| OpenCode๋ ์ ๋ธ๋์น๋ฅผ ๋ง๋ค๊ณ ๋ณ๊ฒฝ ์ฌํญ์ด ๋ด๊ธด merge request๋ฅผ ์์ฑํฉ๋๋ค. |
| - **๋ณด์**: OpenCode๋ GitLab runner์์ ์คํ๋ฉ๋๋ค. |
|
|
| --- |
| |
| |
|
|
| 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๋ฅผ ๊ฒํ ํ๊ณ ํผ๋๋ฐฑ์ ์ ๊ณตํฉ๋๋ค. |
|
|