Compare commits

..

3 Commits

Author SHA1 Message Date
Anthony Lapenna
5588f42504 feat(stacks): use runtime endpoint ID 2020-06-03 13:09:18 +12:00
Anthony Lapenna
4ce19ff818 feat(stacks): use runtime endpoint identifier 2020-06-03 12:00:07 +12:00
Anthony Lapenna
38066ece33 feat(project): re-introduce pull-dog 2020-06-03 11:50:39 +12:00
6 changed files with 38 additions and 23 deletions

View File

@@ -15,7 +15,7 @@ type stackFileResponse struct {
StackFileContent string `json:"StackFileContent"`
}
// GET request on /api/stacks/:id/file
// GET request on /api/stacks/:id/file?endpointId=<endpointId>
func (handler *Handler) stackFile(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
if err != nil {
@@ -29,7 +29,16 @@ func (handler *Handler) stackFile(w http.ResponseWriter, r *http.Request) *httpe
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a stack with the specified identifier inside the database", err}
}
endpoint, err := handler.DataStore.Endpoint().Endpoint(stack.EndpointID)
endpointID, err := request.RetrieveNumericQueryParameter(r, "endpointId", true)
if err != nil {
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
}
endpointIdentifier := stack.EndpointID
if endpointID != 0 {
endpointIdentifier = portainer.EndpointID(endpointID)
}
endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointIdentifier)
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil {

View File

@@ -10,7 +10,7 @@ import (
"github.com/portainer/portainer/api/http/security"
)
// GET request on /api/stacks/:id
// GET request on /api/stacks/:id?endpointId=<endpointId>
func (handler *Handler) stackInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
if err != nil {
@@ -24,7 +24,16 @@ func (handler *Handler) stackInspect(w http.ResponseWriter, r *http.Request) *ht
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a stack with the specified identifier inside the database", err}
}
endpoint, err := handler.DataStore.Endpoint().Endpoint(stack.EndpointID)
endpointID, err := request.RetrieveNumericQueryParameter(r, "endpointId", true)
if err != nil {
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
}
endpointIdentifier := stack.EndpointID
if endpointID != 0 {
endpointIdentifier = portainer.EndpointID(endpointID)
}
endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointIdentifier)
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil {

View File

@@ -59,11 +59,12 @@ func (handler *Handler) stackUpdate(w http.ResponseWriter, r *http.Request) *htt
if err != nil {
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: endpointId", err}
}
if endpointID != int(stack.EndpointID) {
stack.EndpointID = portainer.EndpointID(endpointID)
endpointIdentifier := stack.EndpointID
if endpointID != 0 {
endpointIdentifier = portainer.EndpointID(endpointID)
}
endpoint, err := handler.DataStore.Endpoint().Endpoint(stack.EndpointID)
endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointIdentifier)
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find the endpoint associated to the stack inside the database", err}
} else if err != nil {

View File

@@ -1,5 +1,5 @@
import _ from 'lodash-es';
import { StackViewModel, ExternalStackViewModel } from '../../models/stack';
import { ExternalStackViewModel, StackViewModel } from '../../models/stack';
angular.module('portainer.app').factory('StackService', [
'$q',
@@ -15,10 +15,10 @@ angular.module('portainer.app').factory('StackService', [
'use strict';
var service = {};
service.stack = function (id) {
service.stack = function (id, endpointId) {
var deferred = $q.defer();
Stack.get({ id: id })
Stack.get({ id: id, endpointId: endpointId })
.$promise.then(function success(data) {
var stack = new StackViewModel(data);
deferred.resolve(stack);
@@ -30,10 +30,10 @@ angular.module('portainer.app').factory('StackService', [
return deferred.promise;
};
service.getStackFile = function (id) {
service.getStackFile = function (id, endpointId) {
var deferred = $q.defer();
Stack.getStackFile({ id: id })
Stack.getStackFile({ id: id, endpointId: endpointId })
.$promise.then(function success(data) {
deferred.resolve(data.StackFileContent);
})

View File

@@ -151,15 +151,7 @@ angular.module('portainer.app').controller('StackController', [
var env = FormHelper.removeInvalidEnvVars($scope.stack.Env);
var prune = $scope.formValues.Prune;
var stack = $scope.stack;
// TODO: this is a work-around for stacks created with Portainer version >= 1.17.1
// The EndpointID property is not available for these stacks, we can pass
// the current endpoint identifier as a part of the update request. It will be used if
// the EndpointID property is not defined on the stack.
var endpointId = EndpointProvider.endpointID();
if (stack.EndpointId === 0) {
stack.EndpointId = endpointId;
}
stack.EndpointId = EndpointProvider.endpointID();
$scope.state.actionInProgress = true;
StackService.updateStack(stack, stackFile, env, prune)
@@ -199,7 +191,7 @@ angular.module('portainer.app').controller('StackController', [
});
$q.all({
stack: StackService.stack(id),
stack: StackService.stack(id, EndpointProvider.endpointID()),
groups: GroupService.groups(),
})
.then(function success(data) {
@@ -208,7 +200,7 @@ angular.module('portainer.app').controller('StackController', [
$scope.stack = stack;
return $q.all({
stackFile: StackService.getStackFile(id),
stackFile: StackService.getStackFile(id, EndpointProvider.endpointID()),
resources: stack.Type === 1 ? retrieveSwarmStackResources(stack.Name, agentProxy) : retrieveComposeStackResources(stack.Name),
});
})

4
pull-dog.json Normal file
View File

@@ -0,0 +1,4 @@
{
"dockerComposeYmlFilePaths": ["docker-compose.pull-dog.yml"],
"isLazy": true
}