diff --git a/api-docs.yml b/api-docs.yml
index ebbe46156..9443143ba 100644
--- a/api-docs.yml
+++ b/api-docs.yml
@@ -3,7 +3,7 @@ swagger: '2.0'
info:
title: SEMAPHORE
description: Semaphore API
- version: "2.2.0"
+ version: "2.2.1"
host: localhost:3000
@@ -231,6 +231,8 @@ definitions:
type: string
ssh_key:
type: string
+ path:
+ type: string
keys:
type: array
items:
@@ -672,6 +674,9 @@ definitions:
example: master
ssh_key_id:
type: integer
+ path:
+ type: string
+ example: deployment/ansible
Repository:
type: object
properties:
@@ -690,6 +695,9 @@ definitions:
example: master
ssh_key_id:
type: integer
+ path:
+ type: string
+ example: deployment/ansible
Task:
type: object
diff --git a/db/Inventory.go b/db/Inventory.go
index bee18ae76..888664876 100644
--- a/db/Inventory.go
+++ b/db/Inventory.go
@@ -1,5 +1,7 @@
package db
+import "path"
+
type InventoryType string
const (
@@ -42,11 +44,15 @@ type Inventory struct {
}
func (e Inventory) GetFilename() string {
+ pathPrefix := ""
+ if e.Repository != nil {
+ pathPrefix = e.Repository.Path
+ }
if e.Type != InventoryFile {
- return ""
+ return pathPrefix
}
- return e.Inventory
+ return path.Join(pathPrefix, e.Inventory)
//return strings.TrimPrefix(e.Inventory, "/")
}
diff --git a/db/Migration.go b/db/Migration.go
index 96fcb874e..ca6642986 100644
--- a/db/Migration.go
+++ b/db/Migration.go
@@ -81,6 +81,7 @@ func GetMigrations() []Migration {
{Version: "2.12.3"},
{Version: "2.12.4"},
{Version: "2.12.5"},
+ {Version: "2.12.6"},
}
}
diff --git a/db/Repository.go b/db/Repository.go
index 114d9fb8b..2977e8241 100644
--- a/db/Repository.go
+++ b/db/Repository.go
@@ -31,6 +31,7 @@ type Repository struct {
SSHKeyID int `db:"ssh_key_id" json:"ssh_key_id" binding:"required" backup:"-"`
SSHKey AccessKey `db:"-" json:"-" backup:"-"`
+ Path string `db:"path" json:"path" backup:"-"`
}
func (r Repository) ClearCache() error {
@@ -68,6 +69,10 @@ func (r Repository) GetDirName(templateID int) string {
return r.getDirNamePrefix() + strconv.Itoa(templateID)
}
+func (r Repository) GetAnsiblePath(templateID int) string {
+ return path.Join(r.GetFullPath(templateID), r.Path)
+}
+
func (r Repository) GetFullPath(templateID int) string {
if r.GetType() == RepositoryLocal {
return r.GetGitURL()
diff --git a/db/sql/migrations/v2.12.6.sql b/db/sql/migrations/v2.12.6.sql
new file mode 100644
index 000000000..3d056b8f1
--- /dev/null
+++ b/db/sql/migrations/v2.12.6.sql
@@ -0,0 +1 @@
+alter table `project__repository` add column path text not null;
\ No newline at end of file
diff --git a/db/sql/repository.go b/db/sql/repository.go
index 1c2ed5247..d10b150d2 100644
--- a/db/sql/repository.go
+++ b/db/sql/repository.go
@@ -63,11 +63,12 @@ func (d *SqlDb) UpdateRepository(repository db.Repository) error {
}
_, err = d.exec(
- "update project__repository set name=?, git_url=?, git_branch=?, ssh_key_id=? where id=?",
+ "update project__repository set name=?, git_url=?, git_branch=?, ssh_key_id=?, path=? where id=?",
repository.Name,
repository.GitURL,
repository.GitBranch,
repository.SSHKeyID,
+ repository.Path,
repository.ID)
return err
@@ -82,12 +83,13 @@ func (d *SqlDb) CreateRepository(repository db.Repository) (newRepo db.Repositor
insertID, err := d.insert(
"id",
- "insert into project__repository(project_id, git_url, git_branch, ssh_key_id, name) values (?, ?, ?, ?, ?)",
+ "insert into project__repository(project_id, git_url, git_branch, ssh_key_id, name, path) values (?, ?, ?, ?, ?, ?)",
repository.ProjectID,
repository.GitURL,
repository.GitBranch,
repository.SSHKeyID,
- repository.Name)
+ repository.Name,
+ repository.Path)
if err != nil {
return
diff --git a/db_lib/AnsibleApp.go b/db_lib/AnsibleApp.go
index 93399434b..3ae79e71c 100644
--- a/db_lib/AnsibleApp.go
+++ b/db_lib/AnsibleApp.go
@@ -87,7 +87,7 @@ func (t *AnsibleApp) getRepoPath() string {
Client: CreateDefaultGitClient(),
}
- return repo.GetFullPath()
+ return repo.GetAnsiblePath()
}
func (t *AnsibleApp) installGalaxyRequirementsFile(requirementsType GalaxyRequirementsType, requirementsFilePath string) error {
diff --git a/db_lib/AnsiblePlaybook.go b/db_lib/AnsiblePlaybook.go
index 43051751f..791ef313c 100644
--- a/db_lib/AnsiblePlaybook.go
+++ b/db_lib/AnsiblePlaybook.go
@@ -20,7 +20,7 @@ type AnsiblePlaybook struct {
func (p AnsiblePlaybook) makeCmd(command string, args []string, environmentVars []string) *exec.Cmd {
cmd := exec.Command(command, args...) //nolint: gas
- cmd.Dir = p.GetFullPath()
+ cmd.Dir = p.getAnsiblePath()
cmd.Env = append(cmd.Env, "PYTHONUNBUFFERED=1")
cmd.Env = append(cmd.Env, "ANSIBLE_FORCE_COLOR=True")
@@ -82,7 +82,7 @@ func (p AnsiblePlaybook) RunGalaxy(args []string) error {
return p.runCmd("ansible-galaxy", args)
}
-func (p AnsiblePlaybook) GetFullPath() (path string) {
- path = p.Repository.GetFullPath(p.TemplateID)
+func (p AnsiblePlaybook) getAnsiblePath() (path string) {
+ path = p.Repository.GetAnsiblePath(p.TemplateID)
return
}
diff --git a/db_lib/GitRepository.go b/db_lib/GitRepository.go
index 2aabaa18f..af002b69b 100644
--- a/db_lib/GitRepository.go
+++ b/db_lib/GitRepository.go
@@ -34,6 +34,10 @@ type GitRepository struct {
Client GitClient
}
+func (r GitRepository) GetAnsiblePath() string {
+ return path.Join(r.GetFullPath(), r.Repository.Path)
+}
+
func (r GitRepository) GetFullPath() string {
if r.TmpDirName != "" {
return path.Join(util.Config.TmpPath, r.TmpDirName)
diff --git a/db_lib/TerraformApp.go b/db_lib/TerraformApp.go
index 44b39f821..ddd558763 100644
--- a/db_lib/TerraformApp.go
+++ b/db_lib/TerraformApp.go
@@ -88,7 +88,7 @@ func (t *TerraformApp) runCmd(command string, args []string) error {
}
func (t *TerraformApp) GetFullPath() string {
- return path.Join(t.Repository.GetFullPath(t.Template.ID), strings.TrimPrefix(t.Template.Playbook, "/"))
+ return path.Join(t.Repository.GetAnsiblePath(t.Template.ID), strings.TrimPrefix(t.Template.Playbook, "/"))
}
func (t *TerraformApp) SetLogger(logger task_logger.Logger) task_logger.Logger {
diff --git a/services/project/backup_test.go b/services/project/backup_test.go
index c33ecadb8..b5d4fd0fa 100644
--- a/services/project/backup_test.go
+++ b/services/project/backup_test.go
@@ -37,6 +37,7 @@ func TestBackupProject(t *testing.T) {
Name: "Test",
GitURL: "git@example.com:test/test",
GitBranch: "master",
+ Path: "deployment/ansible",
})
assert.NoError(t, err)
diff --git a/web/src/components/RepositoryForm.vue b/web/src/components/RepositoryForm.vue
index a5a11c068..d2d2d5ea5 100644
--- a/web/src/components/RepositoryForm.vue
+++ b/web/src/components/RepositoryForm.vue
@@ -93,6 +93,15 @@
+
+
+
diff --git a/web/src/lang/en.js b/web/src/lang/en.js
index 10585c417..5cc05f353 100644
--- a/web/src/lang/en.js
+++ b/web/src/lang/en.js
@@ -306,4 +306,5 @@ export default {
status_success: 'Success',
status_failed: 'Failed',
status_stopped: 'Stopped',
+ invalidPath: 'Invalid path',
};
diff --git a/web/src/views/project/Repositories.vue b/web/src/views/project/Repositories.vue
index e5a63f243..7412f9b21 100644
--- a/web/src/views/project/Repositories.vue
+++ b/web/src/views/project/Repositories.vue
@@ -63,6 +63,10 @@
{{ keys.find((k) => k.id === item.ssh_key_id).name }}
+
+ {{ item.path }}
+
+
@@ -104,7 +108,7 @@ export default {
return [{
text: this.$i18n.t('name'),
value: 'name',
- width: '25%',
+ width: '20%',
},
{
text: this.$i18n.t('gitUrl'),
@@ -114,7 +118,12 @@ export default {
{
text: this.$i18n.t('sshKey'),
value: 'ssh_key_id',
- width: '25%',
+ width: '15%',
+ },
+ {
+ text: this.$i18n.t('path'),
+ value: 'path',
+ width: '15%',
},
{
text: this.$i18n.t('actions'),