Skip to content

Commit

Permalink
be explicit about project tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
kylegalbraith committed Nov 17, 2023
1 parent 1954f57 commit 558d9df
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions content/integrations/gitlab-ci.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It is also possible to generate a user access token that can be injected into yo

## Configuration

To build a Docker image from GitLab, you must set the `DEPOT_TOKEN` environment variable in your CI/CD settings for your repository. You can do this through the UI for your repository via [this documentation](https://docs.gitlab.com/ee/ci/variables/index.html).
To build a Docker image from GitLab, you must set the `DEPOT_TOKEN` environment variable in your CI/CD settings for your repository. You can do this through the UI for your repository via [this documentation](https://docs.gitlab.com/ee/ci/variables/index.html). We recommend using a [project token](/docs/cli/authentication#project-tokens).

In addition, you must also install the `depot` CLI before you run `depot build`.

Expand All @@ -31,6 +31,7 @@ build-image:
script:
- depot build .
variables:
# Pass project token or user access token
DEPOT_TOKEN: $DEPOT_TOKEN
```
Expand All @@ -48,7 +49,7 @@ You then inject that file before the build, which allows `depot build . --push`

**Note:** This requires configuring an additional CI/CD variable, but it avoids using Docker-in-Docker.

```yaml
```yaml showLineNumbers
build-image:
before_script:
- curl https://depot.dev/install-cli.sh | DEPOT_INSTALL_DIR=/usr/local/bin sh
Expand All @@ -57,14 +58,15 @@ build-image:
script:
- depot build -t registry.gitlab.com/repo/image:tag . --push
variables:
# Pass project token or user access token
DEPOT_TOKEN: $DEPOT_TOKEN
```

#### Option 2: Using Docker-in-Docker

This example demonstrates using the [Docker-in-Docker](https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor) executor. This method allows you to install the `depot` CLI in the `before_script` block and use `docker login` to authenticate to whichever registry you use.

```yaml
```yaml showLineNumbers
image: docker:20.10.16
services:
- docker:20.10.16-dind
Expand All @@ -80,5 +82,6 @@ build-image:
- echo "$DOCKER_REGISTRY_PASS" | docker login registry.gitlab.com --username <your-username> --password-stdin
- depot build --project <your-project-id> -t registry.gitlab.com/repo/image:tag . --push
variables:
# Pass project token or user access token
DEPOT_TOKEN: $DEPOT_TOKEN
```

0 comments on commit 558d9df

Please sign in to comment.