-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathbuildsform.vue
173 lines (160 loc) · 4.85 KB
/
buildsform.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<template>
<div>
<v-dialog
v-model="dialog"
max-width="600"
>
<template v-slot:activator="{ props: activatorProps }">
<v-btn
block
prepend-icon="mdi-wrench"
text="Build"
color="secondary"
v-bind="activatorProps"
></v-btn>
</template>
<v-card
prepend-icon="mdi-wrench"
title="New Build"
>
<v-card-text>
<v-row dense>
<v-col
cols="12"
sm="6"
>
<v-select
:items="['nixpacks', 'dockerfile', 'buildpacks']"
label="Build strategy*"
description="The strategy to build the source code"
auto-select-first
required
v-model="form.buildstrategy"
@update:modelValue="changedBuildStrategy"
></v-select>
</v-col>
<v-col
cols="12"
sm="6"
>
<v-combobox
label="Branch/Tag/Commit*"
description="The reference to the source code"
:items="references"
v-model="form.reference"
></v-combobox>
</v-col>
<v-col
cols="12"
sm="6"
>
<v-text-field
v-if="form.buildstrategy === 'dockerfile' || form.buildstrategy === 'nixpacks'"
label="Dockerfile Path"
description="Path to the Dockerfile in the source code"
v-model="form.dockerfilePath"
></v-text-field>
</v-col>
</v-row>
<small class="text-caption text-medium-emphasis">*indicates required field</small>
</v-card-text>
<v-divider></v-divider>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
text="Cancel"
variant="plain"
@click="dialog = false"
></v-btn>
<v-btn
color="primary"
text="Build"
variant="tonal"
@click="saveBuild"
></v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script lang="ts">
import axios from "axios";
import { defineComponent } from 'vue'
export default defineComponent({
name: 'BuildsForm',
props: {
pipeline: {
type: String,
default: "MISSING"
},
phase: {
type: String,
default: "MISSING"
},
app: {
type: String,
default: "MISSING"
},
appData: {
type: Object,
}
},
data: () => ({
dialog: false,
form: {
buildstrategy: 'dockerfile',
reference: '',
dockerfilePath: 'Dockerfile'
},
references: [] as string[],
}),
mounted() {
this.loadReferences()
console.log('BuildsForm', this.pipeline, this.phase, this.app, this.appData)
},
methods: {
changedBuildStrategy() {
console.log('changedBuildStrategy', this.form.buildstrategy)
if (this.form.buildstrategy === 'nixpacks') {
this.form.dockerfilePath = '.nixpacks/Dockerfile'
} else {
this.form.dockerfilePath = 'Dockerfile'
}
},
loadReferences() {
const repoB64 = btoa(this.appData?.spec.gitrepo.ssh_url)
//const provider = this.appData?.spec.gitrepo.provider
const provider = "github" // TODO: FIX: get provider from appData
axios.get(`/api/repo/${provider}/${repoB64}/references`)
.then(response => {
this.references = response.data
})
.catch(error => {
console.log('Error loading references', error)
})
},
saveBuild() {
//console.log('Build', this.pipeline, this.phase, this.app, this.form, this.appData)
let repository = this.appData?.spec.gitrepo.ssh_url
if (!this.appData?.spec.gitrepo.private) {
//repository = this.appData?.spec.gitrepo.ssh_url.replace('git@', 'https://')
repository = this.appData?.spec.gitrepo.clone_url
}
const body = {
buildstrategy: this.form.buildstrategy,
repository: repository,
reference: this.form.reference,
dockerfilePath: this.form.dockerfilePath
}
axios.post(`/api/deployments/build/${this.pipeline}/${this.phase}/${this.app}`, body)
.then(response => {
//console.log('Build submitted', response.data)
this.dialog = false
})
.catch(error => {
console.log('Error submitting build', error)
})
}
}
})
</script>