github.com/joselitofilho/goreleaser@v0.155.1-0.20210123221854-e4891856c593/www/docs/ci/gitlab.md (about)

     1  # GitLab CI
     2  
     3  To create GitLab releases and push images to a Docker registry, add a file
     4  `.gitlab-ci.yml` to the root of the project:
     5  
     6  ```yaml
     7  stages:
     8    - release
     9  
    10  release:
    11    stage: release
    12    image: docker:stable
    13    services:
    14      - docker:dind
    15  
    16    variables:
    17      # Optionally use GitLab's built-in image registry.
    18      # DOCKER_REGISTRY: $CI_REGISTRY
    19      # DOCKER_USERNAME: $CI_REGISTRY_USER
    20      # DOCKER_PASSWORD: $CI_REGISTRY_PASSWORD
    21  
    22      # Or, use any registry, including the official one.
    23      DOCKER_REGISTRY: https://index.docker.io/v1/
    24  
    25      # Disable shallow cloning so that goreleaser can diff between tags to
    26      # generate a changelog.
    27      GIT_DEPTH: 0
    28  
    29    # Only run this release job for tags, not every commit (for example).
    30    only:
    31      refs:
    32        - tags
    33  
    34    script: |
    35      # GITLAB_TOKEN is needed to create GitLab releases.
    36      # DOCKER_* are needed to push Docker images.
    37      docker run --rm --privileged \
    38        -v $PWD:/go/src/gitlab.com/YourGitLabUser/YourGitLabRepo \
    39        -w /go/src/gitlab.com/YourGitLabUser/YourGitLabRepo \
    40        -v /var/run/docker.sock:/var/run/docker.sock \
    41        -e DOCKER_USERNAME -e DOCKER_PASSWORD -e DOCKER_REGISTRY  \
    42        -e GITLAB_TOKEN \
    43        goreleaser/goreleaser release --rm-dist
    44  ```
    45  
    46  In GitLab CI settings, add variables for `DOCKER_REGISTRY`, `DOCKER_USERNAME`,
    47  and `DOCKER_PASSWORD` if you aren't using the GitLab image registry. If you are
    48  using the GitLab image registry, you don't need to set these.
    49  
    50  Add a variable `GITLAB_TOKEN` if you are using [GitLab
    51  releases](https://docs.gitlab.com/ce/user/project/releases/). The value should
    52  be an API token with `api` scope for a user that has access to the project.
    53  
    54  The secret variables, `DOCKER_PASSWORD` and `GITLAB_TOKEN`, should be masked.
    55  Optionally, you might want to protect them if the job that uses them will only
    56  be run on protected branches or tags.
    57  
    58  Make sure the `image_templates` in the file `.goreleaser.yml` reflect that
    59  custom registry!
    60  
    61  Example:
    62  
    63  ```yaml
    64  dockers:
    65  -
    66    goos: linux
    67    goarch: amd64
    68    image_templates:
    69    - 'registry.gitlab.com/Group/Project:{{ .Tag }}'
    70    - 'registry.gitlab.com/Group/Project:latest'
    71  ```
    72  
    73  ## How does it look like?
    74  
    75  You can check [this example repository](https://gitlab.com/goreleaser/example) for a real world example.
    76  
    77  <a href="https://gitlab.com/goreleaser/example/-/releases">
    78    <figure>
    79      <img src="https://img.carlosbecker.dev/goreleaser-gitlab.png"/>
    80      <figcaption>Example release on GitLab.</figcaption>
    81    </figure>
    82  </a>