Skip to content

Commit a3f55d4

Browse files
authored
Merge pull request #30 from veertuinc/release/v1.3.0
release/v1.3.0
2 parents 20a527a + ccda77c commit a3f55d4

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

cmd/anka-cloud-gitlab-executor/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package main
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"os"
78
"os/signal"
89
"syscall"
910

1011
"github.com/veertuinc/anka-cloud-gitlab-executor/internal/command"
1112
"github.com/veertuinc/anka-cloud-gitlab-executor/internal/gitlab"
1213
"github.com/veertuinc/anka-cloud-gitlab-executor/internal/log"
14+
"github.com/veertuinc/anka-cloud-gitlab-executor/internal/version"
1315
)
1416

1517
var (
@@ -27,6 +29,12 @@ func main() {
2729
}
2830

2931
func run() int {
32+
33+
if len(os.Args) > 1 && os.Args[1] == "--version" {
34+
fmt.Printf("%s", version.Get())
35+
return 0
36+
}
37+
3038
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM)
3139
defer stop()
3240

internal/command/cleanup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func executeCleanup(ctx context.Context, env gitlab.Environment) error {
4141

4242
controller := ankacloud.NewController(apiClient)
4343

44-
instance, err := controller.GetInstanceByExternalId(ctx, env.GitlabJobId)
44+
instance, err := controller.GetInstanceByExternalId(ctx, env.GitlabJobUrl)
4545
if err != nil {
46-
return fmt.Errorf("failed to get instance by external id %q: %w", env.GitlabJobId, err)
46+
return fmt.Errorf("failed to get instance by external id %q: %w", env.GitlabJobUrl, err)
4747
}
4848
log.Debugf("instance id: %s\n", instance.Id)
4949

internal/command/prepare.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func executePrepare(ctx context.Context, env gitlab.Environment) error {
5454

5555
req := ankacloud.CreateInstanceRequest{
5656
TemplateId: templateId,
57-
ExternalId: env.GitlabJobId,
57+
ExternalId: env.GitlabJobUrl,
5858
Tag: env.TemplateTag,
5959
NodeId: env.NodeId,
6060
Priority: env.Priority,
@@ -67,7 +67,12 @@ func executePrepare(ctx context.Context, env gitlab.Environment) error {
6767
VramMb: env.VmVramMb,
6868
}
6969

70-
log.Colorf("Creating macOS VM with Template %q -- please be patient...", template)
70+
var tagName string
71+
if env.TemplateTag == "" {
72+
tagName = "(latest)"
73+
}
74+
75+
log.Colorf("Creating macOS VM with Template %q and Tag %q -- please be patient...", template, tagName)
7176
log.Debugf("payload %+v\n", req)
7277
instanceId, err := controller.CreateInstance(ctx, req)
7378
if err != nil {

internal/command/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func executeRun(ctx context.Context, env gitlab.Environment, args []string) erro
4343

4444
controller := ankacloud.NewController(apiClient)
4545

46-
instance, err := controller.GetInstanceByExternalId(ctx, env.GitlabJobId)
46+
instance, err := controller.GetInstanceByExternalId(ctx, env.GitlabJobUrl)
4747
if err != nil {
48-
return fmt.Errorf("failed to get instance by external id %q: %w", env.GitlabJobId, err)
48+
return fmt.Errorf("failed to get instance by external id %q: %w", env.GitlabJobUrl, err)
4949
}
5050

5151
var nodeSshPort string

internal/gitlab/vars.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
varVmVcpu = ankaVar("VM_VCPU")
4444

4545
// Gitlab vars
46-
varGitlabJobId = gitlabVar("CI_JOB_ID")
46+
varGitlabJobUrl = gitlabVar("CI_JOB_URL")
4747
varGitlabJobStatus = gitlabVar("CI_JOB_STATUS")
4848
)
4949

@@ -64,7 +64,7 @@ type Environment struct {
6464
SSHPassword string
6565
SSHAttempts int
6666
SSHConnectionAttemptDelay int
67-
GitlabJobId string
67+
GitlabJobUrl string
6868
CustomHttpHeaders map[string]string
6969
KeepAliveOnError bool
7070
GitlabJobStatus jobStatus
@@ -105,8 +105,8 @@ func InitEnv() (Environment, error) {
105105
return e, fmt.Errorf("%w %q: missing http prefix", ErrInvalidVar, e.ControllerURL)
106106
}
107107

108-
if e.GitlabJobId, ok = os.LookupEnv(varGitlabJobId); !ok {
109-
return e, fmt.Errorf("%w: %s", ErrMissingVar, varGitlabJobId)
108+
if e.GitlabJobUrl, ok = os.LookupEnv(varGitlabJobUrl); !ok {
109+
return e, fmt.Errorf("%w: %s", ErrMissingVar, varGitlabJobUrl)
110110
}
111111

112112
if os.Getenv(varSshUserName) != "" {

internal/gitlab/vars_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestControllerWithTrailingSlash(t *testing.T) {
1111
os.Setenv(varControllerURL, "http://fake-controller-url/")
12-
os.Setenv(varGitlabJobId, "fake-gitlab-job-id")
12+
os.Setenv(varGitlabJobUrl, "fake-gitlab-job-url")
1313
defer os.Clearenv()
1414

1515
env, err := InitEnv()
@@ -24,7 +24,7 @@ func TestControllerWithTrailingSlash(t *testing.T) {
2424

2525
func TestCustomHttpHeadersEnvVar(t *testing.T) {
2626
os.Setenv(varControllerURL, "http://fake-controller-url")
27-
os.Setenv(varGitlabJobId, "fake-gitlab-job-id")
27+
os.Setenv(varGitlabJobUrl, "fake-gitlab-job-url")
2828
os.Setenv(varCustomHTTPHeaders, "{\"fake-header\":\"fake-value\", \"fake-header2\":\"fake-value2\"}")
2929
defer os.Clearenv()
3030
env, err := InitEnv()
@@ -74,8 +74,8 @@ func TestGitlabJobIdMissing(t *testing.T) {
7474
if !errors.Is(err, ErrMissingVar) {
7575
t.Errorf("expected error %q, got %q", ErrMissingVar, err)
7676
}
77-
if !strings.Contains(err.Error(), varGitlabJobId) {
78-
t.Errorf("expected error to contain %q, got %q", varGitlabJobId, err)
77+
if !strings.Contains(err.Error(), varGitlabJobUrl) {
78+
t.Errorf("expected error to contain %q, got %q", varGitlabJobUrl, err)
7979
}
8080
}
8181

@@ -103,7 +103,7 @@ func TestInvalidVram(t *testing.T) {
103103
for _, tc := range testCases {
104104
os.Clearenv()
105105
os.Setenv(varControllerURL, "http://fake-controller-url")
106-
os.Setenv(varGitlabJobId, "fake-gitlab-job-id")
106+
os.Setenv(varGitlabJobUrl, "fake-gitlab-job-url")
107107

108108
os.Setenv(varVmVcpu, tc.vram)
109109

@@ -141,8 +141,7 @@ func TestInvalidVcpu(t *testing.T) {
141141
for _, tc := range testCases {
142142
os.Clearenv()
143143
os.Setenv(varControllerURL, "http://fake-controller-url")
144-
os.Setenv(varGitlabJobId, "fake-gitlab-job-id")
145-
144+
os.Setenv(varGitlabJobUrl, "fake-gitlab-job-url")
146145
os.Setenv(varVmVcpu, tc.vcpu)
147146

148147
_, err := InitEnv()

0 commit comments

Comments
 (0)