semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.65k stars 1.07k forks source link

Force requirements install #1579

Open Arkhenys opened 1 year ago

Arkhenys commented 1 year ago

Hello,

I recently figured that when using Semaphore v2.9.37, requirements are not forcibly installed. I found this comment, a bit old now https://github.com/ansible-semaphore/semaphore/issues/682#issuecomment-897026897 where it is indicated that requirements are forcibly installed using ansible-galaxy install -r roles/requirements.yml --force

Did I miss something in my configuration ? Is there a way to forcibly install roles and collections requirements using Semaphore ?

Thanks a lot for your help :)

Arkhenys commented 1 year ago

Hello,

To be clearer, it seems that Semaphore doesn't even try to install requirements if nothing changed directly in the requirements.yml file. I think we should have the option, as a user, to specify if we want a requirements installation or if we want it to be skipped.

Arkhenys commented 1 year ago

Good afternoon @fiftin

Any plan to add the possibility to reinstall requirements for each task launched ? The current behavior is really annoying as we have to find a workaround to indicate to Semaphore that the requirements file has changed to trigger requiremetns installation.

The current problem is that if there is no change detected in requirements file, requirements won't be reinstalled. But for example, in that case:

---
#===============================================================================
# Ansible collections
#===============================================================================
collections:
  - name: git@gitlab.mydomain.tld:project/path/to/collections/my_collection/collection.git
    type: git
    version: my_version

If I made a change in the code of collection.git on "my_version" branch, there is no change in the requirements.yml file but the code of the collection changed. However, semaphore won't reinstall requirements because no changes on the requirements file will be found. Adding the possibility to reinstall requirements even with no detected changes in requirements file would be really appreciated.

Thanks for your help, have a good day :)

Arkhenys commented 1 year ago

Hello @fiftin, any news on it ?

manzomanze commented 4 months ago

I am really interested in the force reinstall of the collections like @Arkhenys, any news @fiftin ?

pshepelev commented 4 months ago

+1 @fiftin

occhioni-esteco commented 3 months ago

+1 @fiftin

maverick1982 commented 3 months ago

+1 @fiftin

MascHman commented 3 months ago

+1

daniel-soler commented 2 months ago

+1 @fiftin

steadfasterX commented 2 months ago

@fiftin it seems there are a lot (like me) wanting to see this added .. so I really hope u find the time integrating it ;)

hagaram commented 5 days ago

+1

hagaram commented 4 days ago

i dont quite understand the decision behind this behaviour or that it is not possible to override. But this is what I ended up doing. semaphore.patch

diff '--color=auto' -ruN semaphore-2.10.35/db_lib/AnsibleApp.go semaphore-2.10.35-patched/db_lib/AnsibleApp.go
--- semaphore-2.10.35/db_lib/AnsibleApp.go  2024-10-27 23:14:27.000000000 +0100
+++ semaphore-2.10.35-patched/db_lib/AnsibleApp.go  2024-11-14 07:44:24.446242879 +0100
@@ -9,6 +9,7 @@

    "github.com/semaphoreui/semaphore/db"
    "github.com/semaphoreui/semaphore/pkg/task_logger"
+   "github.com/semaphoreui/semaphore/util"
 )

 func getMD5Hash(filepath string) (string, error) {
@@ -26,6 +27,10 @@
 }

 func hasRequirementsChanges(requirementsFilePath string, requirementsHashFilePath string) bool {
+   if util.Config.AnsibleForceInstallRequirements {
+       return true
+   }
+   
    oldFileMD5HashBytes, err := os.ReadFile(requirementsHashFilePath)
    if err != nil {
        return true
diff '--color=auto' -ruN semaphore-2.10.35/util/config.go semaphore-2.10.35-patched/util/config.go
--- semaphore-2.10.35/util/config.go    2024-10-27 23:14:27.000000000 +0100
+++ semaphore-2.10.35-patched/util/config.go    2024-11-14 07:44:24.447242871 +0100
@@ -196,6 +196,7 @@
    // feature switches
    PasswordLoginDisable     bool `json:"password_login_disable,omitempty" env:"SEMAPHORE_PASSWORD_LOGIN_DISABLED"`
    NonAdminCanCreateProject bool `json:"non_admin_can_create_project,omitempty" env:"SEMAPHORE_NON_ADMIN_CAN_CREATE_PROJECT"`
+   AnsibleForceInstallRequirements bool `json:"ansible_force_install_requirements,omitempty" env:"SEMAPHORE_ANSIBLE_FORCE_INSTALL_REQUIREMENTS"`

    UseRemoteRunner bool `json:"use_remote_runner,omitempty" env:"SEMAPHORE_USE_REMOTE_RUNNER"`

Snippet of build from Gitlab CI

     - git clone https://github.com/semaphoreui/semaphore.git
    - cp deployment/semaphore_docker/src/semaphore.patch semaphore/
    - cd semaphore
    - git checkout v${SEMAPHORE_VERSION}
    - patch -p1 < semaphore.patch
    - docker buildx build --pull -f deployment/docker/server/Dockerfile --build-arg SEMAPHORE_VERSION=${SEMAPHORE_VERSION} --tag ${CI_REGISTRY_IMAGE}/semaphore:v${SEMAPHORE_VERSION} .
    - docker push ${CI_REGISTRY_IMAGE}/semaphore:v${SEMAPHORE_VERSION}

Now I can configure semaphore to skip the check process. With ENV variable e.g. SEMAPHORE_ANSIBLE_FORCE_INSTALL_REQUIREMENTS Or in config file e.g. ansible_force_install_requirements