# GitLab 與 Drone

安裝 GitLab

```
mkdir GitLab && cd GitLab
curl https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml -O
docker-compose up
```

> 如果出現 ERROR: manifest for sameersbn/gitlab:13.0.7 not found:
>
> &#x20;把 docker-compose.yml 的gitlab image 版本改為&#x20;
>
> > sameersbn/gitlab:latest

安裝好輸入 docker ps 確認

![](https://2356031413-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0u4DAqfidGmTt67qrG%2F-MDXYc-fmsC6lD60rl7D%2F-MDXb8TsFvkGhclKWjM-%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202020-07-31%20%E4%B8%8A%E5%8D%8810.03.27.png?alt=media\&token=7bdb3574-354a-4e98-b2cb-4c91ce70c494)

進入 `localhost:10080`

![](https://2356031413-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0u4DAqfidGmTt67qrG%2F-MDXYc-fmsC6lD60rl7D%2F-MDXbAp7WsE2URxtFV7q%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202020-07-31%20%E4%B8%8A%E5%8D%8810.03.31.png?alt=media\&token=c1a388b2-2337-46a6-9c01-921eba3dda0b)

預設會先請你輸入密碼，使用者名稱為 root

> 之後也可輸入 email 創建 user，不過不會收到 email

如果想要忘記密碼等傳送email功能需要設定 SMTP server

{% embed url="<https://docs.gitlab.com/omnibus/settings/smtp.html>" %}

## Gitlab clone 專案 with access token

通常在部署主機上需要 clone 專案，但使用個人的 ssh key 權限過大，所以可以創建專案的 access token，之後如下 clone 專案。

```
git clone https://oauth2:ACCESS_TOKEN@domain.com/.../package.git
```

## 安裝 Drone CI

> 這邊如果還沒綁定 domain，建議先把 localhost 的 GitLab 與等下會用的 drone 的 port 都用 ngrok 產生 domain ，這樣才能正常使用

{% embed url="<https://docs.drone.io/server/provider/gitlab/>" %}

1.先去新增 OAuth Application : <http://localhost:10080/profile/applications>

> callback url 記得在最後面加上 /login

2.然後產生 share secret `openssl rand -hex 16`

3.新增 docker-compose.yml

> 這邊如果 GitLab 或 Drone 用 localhost ，之後再 gitLab 連結 drone 時會產生錯誤
>
> Login Failed. Post "<http://localhost:10080/oauth/token>": dial tcp 127.0.0.1:10080: connect: connection refused\`

```
version: '2.3'

services:
  drone-server:
    image: drone/drone:1
    ports:
      - 10081:80
    volumes:
      - ./:/data
    restart: always
    environment:
      - DRONE_SERVER_HOST=66934108131d.ngrok.io
      - DRONE_SERVER_PROTO=https
      - DRONE_RPC_SECRET=131f7e1a919158e42dfdfc74d5552ec3
      - DRONE_AGENTS_ENABLED=true
      # Gitlab Config
      - DRONE_GITLAB_SERVER=http://1ee9b44b230d.ngrok.io
      - DRONE_GITLAB_CLIENT_ID=7f71d69fe5dab5d770a7cf1a56c876e3b6a366ba0b6036c4e320382714e5c84e
      - DRONE_GITLAB_CLIENT_SECRET=9b7e8f676137598590efbbf4081e0bedb949c6df6b2ca29be40b3bfb56bb419a
      - DRONE_LOGS_PRETTY=true
      - DRONE_LOGS_COLOR=true

  drone-runner:
    image: drone/drone-runner-docker:1
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_RPC_HOST=66934108131d.ngrok.io
      - DRONE_RPC_PROTO=http
      - DRONE_RPC_SECRET=131f7e1a919158e42dfdfc74d5552ec3
```

之後連入 drone url 會自動導到 gitLab 連結 drone 畫面，點選 authorize 即會導入到 drone 頁面

![](https://2356031413-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0u4DAqfidGmTt67qrG%2F-MDXsG6fUcZq6-Ghw82V%2F-MDXsMuKokJiuk02s9Uz%2F%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202020-07-31%20%E4%B8%8A%E5%8D%8811.18.58.png?alt=media\&token=33600927-8547-41f3-a26e-2b8ad4133dd1)

4\. 剛才看到 docker-compose 下方的 runner 為用來執行 pipeline的


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://easonwang.gitbook.io/web_advance/zi-dong-hua-bu-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
