go-semantic-release / semantic-release

πŸ“¦πŸš€ semantic-release written in Go
https://go-semantic-release.xyz
MIT License
404 stars 43 forks source link

Docker Image causes issues on gitlab #83

Closed cliedeman closed 2 years ago

cliedeman commented 3 years ago

The entrypoint embedded into the image cause the semantic-release step to be run twice. Once during script and again during after_script on gitlab.

https://github.com/go-semantic-release/semantic-release/blob/master/Dockerfile#L17

Kirbo commented 3 years ago

We currently use it like this:

promote-release:
  stage: promote
  image:
    name: registry.gitlab.com/go-semantic-release/semantic-release:latest
    entrypoint: [""]
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
  script:
    - semantic-release --provider gitlab --version-file
  artifacts:
    paths:
      - .version
Kirbo commented 3 years ago

We currently use it like this:

promote-release:
  stage: promote
  image:
    name: registry.gitlab.com/go-semantic-release/semantic-release:latest
    entrypoint: [""]
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
  script:
    - semantic-release --provider gitlab --version-file
  artifacts:
    paths:
      - .version

Actually this didn't work for us at the moment. Therefore I created a pull request, which I hope should fix this problem. Not completely sure though, since I wasn't able to run it, because I'm getting an error:

[go-semantic-release]: version: 2.13.0
[go-semantic-release]: fork/exec .semrel/linux_amd64/condition-default/1.2.0/condition-default_v1.2.0_linux_amd64: no such file or directory

..I was using my own image, which I tagged to be 2.13.0, found here: https://hub.docker.com/r/kirbownz/semantic-release

Would you happen to know why am I getting this error? Locally running semantic-release on my Mac it works like a charm, but if I run it in a Docker container, I'm getting the error above.

EDIT: Got it narrowed down, it dies on this line pkg/plugin/client.go:67. Cannot use RPC connections inside Docker container?

@christophwitzko ping

christophwitzko commented 3 years ago

@kirbo this is related to the plugin builds. They are dynamically linked and not running on alpine, I will update the build configuration to provide statically linked binaries.

christophwitzko commented 3 years ago

@kirbo The plugins are now recompiled and the latest release of the docker image is working πŸ‘

Kirbo commented 3 years ago

@kirbo The plugins are now recompiled and the latest release of the docker image is working πŸ‘

Nice, thank you! I'll give it a shot in a moment πŸ™‚ Noticed that you didn't include the docker-entrypoint.sh file. That would've (at least should've) fixed the issue mentioned here

christophwitzko commented 3 years ago

@kirbo Ooops, overlooked it. πŸ™ˆ Can you create another pull request? Thanks in advance! ☺️

Kirbo commented 3 years ago

@kirbo Ooops, overlooked it. πŸ™ˆ Can you create another pull request? Thanks in advance! ☺️

Sorry, almost forgot to answer. The image now works, with the exact example I wrote above. I'll try later whether this issue is addressed as well, since I just realised that alpine contains SH anyway, so at least on theory this should work just fine, because we're overwriting the entrypoint with empty anyway:

promote-release:
  stage: promote
  image:
    name: registry.gitlab.com/go-semantic-release/semantic-release:latest
    entrypoint: [""]
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
  before_script:
    - echo "something in before script"
  script:
    - semantic-release --provider gitlab --version-file
  after_script:
    - echo "something else in after script"
    - cat .version
  artifacts:
    paths:
      - .version

But if the container contained the docker-entrypoint.sh, user should not be required to overwrite the entrypoint and should still be able to run other commands as they liked.

I might be wrong as well, not sure πŸ˜› Will have to give this a try.

Kirbo commented 3 years ago

Yup, I can confirm that this works now:

## https://docs.gitlab.com/ce/ci/yaml/README.html
## https://docs.gitlab.com/ee/ci/variables/README.html

stages:
  - promote

promote-release:
  stage: promote
  image:
    name: registry.gitlab.com/go-semantic-release/semantic-release:latest
    entrypoint: [""]
  rules:
    - if: $CI_COMMIT_BRANCH
  before_script:
    - echo "before"
  script:
    - semantic-release --provider gitlab --version-file --allow-initial-development-versions
  after_script:
    - echo "after"
  artifacts:
    paths:
      - .version

Output here:

Running with gitlab-runner 13.6.0-rc1 (d83ac56c)
  on docker-auto-scale <redacted>
Resolving secrets
Preparing the "docker+machine" executor
Using Docker executor with image registry.gitlab.com/go-semantic-release/semantic-release:latest ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/go-semantic-release/semantic-release:latest ...
Using docker image sha256:9c674d3800ff2ad8536f3c0c3c4314a30c51ca67e9cd6678cc362e659a02b955 for registry.gitlab.com/go-semantic-release/semantic-release:latest with digest registry.gitlab.com/go-semantic-release/semantic-release@sha256:39d983d1435d7964e6f459cff9976147ad67de48b432597390fe81f8e7684ac0 ...
Preparing environment
Running on runner-ed2dce3a-project-21677795-concurrent-0 via runner-ed2dce3a-srm-1606117301-f90e3438...
Getting source from Git repository
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/<redacted>/.git/
Created fresh repository.
Checking out 92cf4694 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ echo "before"
before
$ semantic-release --provider gitlab --version-file --allow-initial-development-versions
[go-semantic-release]: version: 2.12.2
[go-semantic-release]: ci-condition plugin: default@1.2.2
[go-semantic-release]: provider plugin: GitLab@1.4.1
[go-semantic-release]: getting default branch...
[go-semantic-release]: found default branch: master
[go-semantic-release]: repo is private
[go-semantic-release]: found current branch: <redacted>
[go-semantic-release]: found current sha: <redacted>
[go-semantic-release]: running CI condition...
[go-semantic-release]: getting latest release...
[go-semantic-release]: found version: 1.0.0
[go-semantic-release]: getting commits...
[go-semantic-release]: analyzing commits...
[go-semantic-release]: commit-analyzer plugin: default@1.3.1
[go-semantic-release]: calculating new version...
[go-semantic-release]: new version: 1.1.0
[go-semantic-release]: generating changelog...
[go-semantic-release]: changelog-generator plugin: default@1.4.1
[go-semantic-release]: creating release...
[go-semantic-release]: done.
Running after_script
Running after script...
$ echo "after"
after
Uploading artifacts for successful job
Uploading artifacts...
.version: found 1 matching files and directories   
Uploading artifacts as "archive" to coordinator... ok  id=<redacted> responseStatus=201 Created token=<redacted>
Cleaning up file based variables
Job succeeded
Kirbo commented 3 years ago

And as suspected, this did not work, without the docker-entrypoint.sh thingy. I'll create a Pull Request out of it soon-ish:

## https://docs.gitlab.com/ce/ci/yaml/README.html
## https://docs.gitlab.com/ee/ci/variables/README.html

stages:
  - promote

promote-release:
  stage: promote
  image: registry.gitlab.com/go-semantic-release/semantic-release:latest
  rules:
    - if: $CI_COMMIT_BRANCH
  before_script:
    - echo "before"
  script:
    - semantic-release --provider gitlab --version-file --allow-initial-development-versions
  after_script:
    - echo "after"
  artifacts:
    paths:
      - .version

Output:

Running with gitlab-runner 13.6.0-rc1 (d83ac56c)
  on docker-auto-scale <redacted>
Resolving secrets
Preparing the "docker+machine" executor
Using Docker executor with image registry.gitlab.com/go-semantic-release/semantic-release:latest ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/go-semantic-release/semantic-release:latest ...
Using docker image sha256:9c674d3800ff2ad8536f3c0c3c4314a30c51ca67e9cd6678cc362e659a02b955 for registry.gitlab.com/go-semantic-release/semantic-release:latest with digest registry.gitlab.com/go-semantic-release/semantic-release@sha256:39d983d1435d7964e6f459cff9976147ad67de48b432597390fe81f8e7684ac0 ...
Preparing environment
Running on runner-0277ea0f-project-21677795-concurrent-0 via runner-0277ea0f-srm-1606117654-f63f3706...
Getting source from Git repository
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/<redacted>/.git/
Created fresh repository.
Checking out <redacted> as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
Error: unknown shorthand flag: 'c' in -c
Usage:
  semantic-release [flags]
Flags:
      --allow-initial-development-versions    semantic-release will start your initial development release at 0.1.0
      --allow-no-changes                      exit with code 0 if no changes are found, useful if semantic-release is automatically run
      --changelog string                      creates a changelog file
      --changelog-generator string            changelog-generator plugin name (default "default")
      --changelog-generator-opt stringArray   options that are passed to the changelog-generator plugin
      --ci-condition string                   ci-condition plugin name (default "gitlab")
      --ci-condition-opt stringArray          options that are passed to the ci-condition plugin
      --commit-analyzer string                commit-analyzer plugin name (default "default")
      --commit-analyzer-opt stringArray       options that are passed to the commit-analyzer plugin
      --download-plugins                      downloads all required plugins if needed
      --dry                                   do not create release
      --files-updater strings                 files-updater plugin names (default [npm])
      --files-updater-opt stringArray         options that are passed to the files-updater plugins
      --ghr                                   create a .ghr file with the parameters for ghr
  -h, --help                                  help for semantic-release
      --hooks strings                         hooks plugin names
      --hooks-opt stringArray                 options that are passed to the hooks plugins
      --maintained-version string             set the maintained version as base for new releases
      --match string                          only consider tags matching the given glob(7) pattern, excluding the "refs/tags/" prefix.
      --no-ci                                 run semantic-release locally
      --prepend-changelog                     if the changelog file already exist the new changelog is prepended
      --prerelease                            flags the release as a prerelease
      --provider string                       provider plugin name (default "gitlab")
      --provider-opt stringArray              options that are passed to the provider plugin
      --show-progress                         shows the plugin download progress
  -t, --token string                          provider token
  -u, --update stringArray                    updates the version of a certain files
  -v, --version                               version for semantic-release
  -f, --version-file                          create a .version file with the new version
unknown shorthand flag: 'c' in -c
Running after_script
Error: unknown shorthand flag: 'c' in -c
Usage:
  semantic-release [flags]
Flags:
      --allow-initial-development-versions    semantic-release will start your initial development release at 0.1.0
      --allow-no-changes                      exit with code 0 if no changes are found, useful if semantic-release is automatically run
      --changelog string                      creates a changelog file
      --changelog-generator string            changelog-generator plugin name (default "default")
      --changelog-generator-opt stringArray   options that are passed to the changelog-generator plugin
      --ci-condition string                   ci-condition plugin name (default "gitlab")
      --ci-condition-opt stringArray          options that are passed to the ci-condition plugin
      --commit-analyzer string                commit-analyzer plugin name (default "default")
      --commit-analyzer-opt stringArray       options that are passed to the commit-analyzer plugin
      --download-plugins                      downloads all required plugins if needed
      --dry                                   do not create release
      --files-updater strings                 files-updater plugin names (default [npm])
      --files-updater-opt stringArray         options that are passed to the files-updater plugins
      --ghr                                   create a .ghr file with the parameters for ghr
  -h, --help                                  help for semantic-release
      --hooks strings                         hooks plugin names
      --hooks-opt stringArray                 options that are passed to the hooks plugins
      --maintained-version string             set the maintained version as base for new releases
      --match string                          only consider tags matching the given glob(7) pattern, excluding the "refs/tags/" prefix.
      --no-ci                                 run semantic-release locally
      --prepend-changelog                     if the changelog file already exist the new changelog is prepended
      --prerelease                            flags the release as a prerelease
      --provider string                       provider plugin name (default "gitlab")
      --provider-opt stringArray              options that are passed to the provider plugin
      --show-progress                         shows the plugin download progress
  -t, --token string                          provider token
  -u, --update stringArray                    updates the version of a certain files
  -v, --version                               version for semantic-release
  -f, --version-file                          create a .version file with the new version
unknown shorthand flag: 'c' in -c
Cleaning up file based variables
ERROR: Job failed: exit code 1
christophwitzko commented 3 years ago

@kirbo Thanks for testing it out. Looking forward to your PR! πŸ‘

cliedeman commented 2 years ago

I think I have an easier solution to this.

Keep the entrypoint.sh but exit early if we detect we are running in gitlab using the GITLAB_CI environment variable

https://docs.gitlab.com/ee/ci/variables/predefined_variables.html