Skip to content

Commit

Permalink
Merge pull request #863 from replicatedhq/move-deploy-app-version-to-go
Browse files Browse the repository at this point in the history
move deployKotsVersion to go
  • Loading branch information
sgalsaleh committed Jul 27, 2020
2 parents bdd3f0f + c98ca32 commit 27d2392
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 18 deletions.
1 change: 1 addition & 0 deletions kotsadm/pkg/apiserver/server.go
Expand Up @@ -98,6 +98,7 @@ func Start() {
r.Path("/api/v1/app/{appSlug}/sequence/{sequence}/preflight/run").Methods("OPTIONS", "POST").HandlerFunc(handlers.StartPreflightChecks)
r.Path("/api/v1/upload").Methods("PUT").HandlerFunc(handlers.UploadExistingApp)
r.Path("/api/v1/download").Methods("GET").HandlerFunc(handlers.DownloadApp)
r.Path("/api/v1/app/{appSlug}/sequence/{sequence}/deploy").Methods("OPTIONS", "POST").HandlerFunc(handlers.DeployAppVersion)
r.Path("/api/v1/app/{appSlug}/sequence/{sequence}/renderedcontents").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetAppRenderedContents)
r.Path("/api/v1/app/{appSlug}/sequence/{sequence}/contents").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetAppContents)
r.Path("/api/v1/app/{appSlug}/cluster/{clusterId}/dashboard").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetAppDashboard)
Expand Down
49 changes: 49 additions & 0 deletions kotsadm/pkg/handlers/deploy.go
@@ -0,0 +1,49 @@
package handlers

import (
"net/http"
"strconv"

"github.com/gorilla/mux"
"github.com/replicatedhq/kots/kotsadm/pkg/app"
"github.com/replicatedhq/kots/kotsadm/pkg/logger"
"github.com/replicatedhq/kots/kotsadm/pkg/version"
)

func DeployAppVersion(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}

if err := requireValidSession(w, r); err != nil {
logger.Error(err)
return
}

appSlug := mux.Vars(r)["appSlug"]
sequence, err := strconv.Atoi(mux.Vars(r)["sequence"])
if err != nil {
logger.Error(err)
w.WriteHeader(500)
return
}

a, err := app.GetFromSlug(appSlug)
if err != nil {
logger.Error(err)
w.WriteHeader(500)
return
}

if err := version.DeployVersion(a.ID, int64(sequence)); err != nil {
logger.Error(err)
w.WriteHeader(500)
return
}

JSON(w, 204, "")
}
22 changes: 15 additions & 7 deletions kotsadm/web/src/components/PreflightResultPage.jsx
Expand Up @@ -5,7 +5,6 @@ import { Helmet } from "react-helmet";
import { withRouter } from "react-router-dom";
import Modal from "react-modal";
import { getKotsPreflightResult, getLatestKotsPreflightResult } from "@src/queries/AppsQueries";
import { deployKotsVersion } from "@src/mutations/AppsMutations";
import Loader from "./shared/Loader";
import PreflightRenderer from "./PreflightRenderer";
import { getPreflightResultState, Utilities } from "../utilities/utilities";
Expand Down Expand Up @@ -43,7 +42,7 @@ class PreflightResultPage extends Component {
return;
}
const sequence = match.params.sequence ? parseInt(match.params.sequence, 10) : 0;
await this.props.deployKotsVersion(preflightResultData.appSlug, sequence, preflightResultData.clusterSlug);
await this.deployKotsVersion(preflightResultData.appSlug, sequence);
}

history.push(`/app/${preflightResultData.appSlug}/version-history`);
Expand All @@ -52,6 +51,20 @@ class PreflightResultPage extends Component {
}
}

deployKotsVersion = async (appSlug, sequence) => {
try {
await fetch(`${window.env.API_ENDPOINT}/app/${appSlug}/sequence/${sequence}/deploy`, {
headers: {
"Authorization": Utilities.getToken(),
"Content-Type": "application/json",
},
method: "POST",
});
} catch(err) {
console.log(err);
}
}

showSkipModal = () => {
this.setState({
showSkipModal: true
Expand Down Expand Up @@ -299,9 +312,4 @@ export default compose(
}
}
}),
graphql(deployKotsVersion, {
props: ({ mutate }) => ({
deployKotsVersion: (upstreamSlug, sequence, clusterSlug) => mutate({ variables: { upstreamSlug, sequence, clusterSlug } })
})
}),
)(PreflightResultPage);
24 changes: 14 additions & 10 deletions kotsadm/web/src/components/apps/AppDetailPage.jsx
Expand Up @@ -9,15 +9,15 @@ import has from "lodash/has";
import withTheme from "@src/components/context/withTheme";
import { getKotsApp, listDownstreamsForApp } from "@src/queries/AppsQueries";
import { isVeleroInstalled } from "@src/queries/SnapshotQueries";
import { createKotsDownstream, deleteKotsDownstream, deployKotsVersion } from "../../mutations/AppsMutations";
import { createKotsDownstream, deleteKotsDownstream } from "../../mutations/AppsMutations";
import { KotsSidebarItem } from "@src/components/watches/WatchSidebarItem";
import { HelmChartSidebarItem } from "@src/components/watches/WatchSidebarItem";
import NotFound from "../static/NotFound";
import Dashboard from "./Dashboard";
import CodeSnippet from "../shared/CodeSnippet";
import DownstreamTree from "../../components/tree/KotsApplicationTree";
import AppVersionHistory from "./AppVersionHistory";
import { isAwaitingResults } from "../../utilities/utilities";
import { isAwaitingResults, Utilities } from "../../utilities/utilities";
import PreflightResultPage from "../PreflightResultPage";
import AppConfig from "./AppConfig";
import AppLicense from "./AppLicense";
Expand Down Expand Up @@ -96,10 +96,19 @@ class AppDetailPage extends Component {
this.props.clearThemeState();
}

makeCurrentRelease = async (upstreamSlug, sequence, clusterSlug) => {
await this.props.deployKotsVersion(upstreamSlug, sequence, clusterSlug).then(() => {
makeCurrentRelease = async (upstreamSlug, sequence) => {
try {
await fetch(`${window.env.API_ENDPOINT}/app/${upstreamSlug}/sequence/${sequence}/deploy`, {
headers: {
"Authorization": Utilities.getToken(),
"Content-Type": "application/json",
},
method: "POST",
});
this.refetchGraphQLData();
})
} catch(err) {
console.log(err);
}
}

toggleDisplayDownloadModal = () => {
Expand Down Expand Up @@ -429,9 +438,4 @@ export default compose(
deleteKotsDownstream: (slug, clusterId) => mutate({ variables: { slug, clusterId } })
})
}),
graphql(deployKotsVersion, {
props: ({ mutate }) => ({
deployKotsVersion: (upstreamSlug, sequence, clusterSlug) => mutate({ variables: { upstreamSlug, sequence, clusterSlug } })
})
}),
)(AppDetailPage);
2 changes: 1 addition & 1 deletion kotsadm/web/src/components/apps/AppVersionHistory.jsx
Expand Up @@ -421,7 +421,7 @@ class AppVersionHistory extends Component {
}
}
}
await this.props.makeCurrentVersion(match.params.slug, version.sequence, clusterSlug);
await this.props.makeCurrentVersion(match.params.slug, version.sequence);
await this.props.data.refetch();
this.setState({ versionToDeploy: null });

Expand Down

0 comments on commit 27d2392

Please sign in to comment.