build: Allow optional "nodeploy" tag to exclude deploy command from bin
authorEric Hagman <emhagman@gmail.com>
Fri, 23 Oct 2020 07:03:41 +0000 (03:03 -0400)
committerGitHub <noreply@github.com>
Fri, 23 Oct 2020 07:03:41 +0000 (09:03 +0200)
Fixes #7826

Dockerfile
commands/deploy.go
commands/nodeploy.go [new file with mode: 0644]
deploy/cloudfront.go
deploy/deploy.go
deploy/deployConfig.go
deploy/deployConfig_test.go
deploy/deploy_azure.go
deploy/deploy_test.go
deploy/google.go
magefile.go

index 528c12e3b0349a207c5007c4bcaae00cc9787b5f..75ed38969455146c8955448ad2477d1b77304011 100755 (executable)
@@ -4,7 +4,7 @@
 
 FROM golang:1.15-alpine AS build
 
-# Optionally set HUGO_BUILD_TAGS to "extended" when building like so:
+# Optionally set HUGO_BUILD_TAGS to "extended" or "nodeploy" when building like so:
 #   docker build --build-arg HUGO_BUILD_TAGS=extended .
 ARG HUGO_BUILD_TAGS
 
index 7133f9a0e686b80e14072eaf42fba1ba88d2ad70..2e155760931bcbfeb7fbb0837b5986127e19d406 100644 (file)
@@ -11,6 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// +build !nodeploy
+
 package commands
 
 import (
diff --git a/commands/nodeploy.go b/commands/nodeploy.go
new file mode 100644 (file)
index 0000000..146a61f
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright 2019 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build nodeploy
+
+package commands
+
+import (
+       "errors"
+       "github.com/spf13/cobra"
+)
+
+var _ cmder = (*deployCmd)(nil)
+
+// deployCmd supports deploying sites to Cloud providers.
+type deployCmd struct {
+       *baseBuilderCmd
+}
+
+func (b *commandsBuilder) newDeployCmd() *deployCmd {
+       cc := &deployCmd{}
+
+       cmd := &cobra.Command{
+               Use:   "deploy",
+               Short: "Deploy your site to a Cloud provider.",
+               Long: `Deploy your site to a Cloud provider.
+
+See https://gohugo.io/hosting-and-deployment/hugo-deploy/ for detailed
+documentation.
+`,
+               RunE: func(cmd *cobra.Command, args []string) error {
+                       return errors.New("build without HUGO_BUILD_TAGS=nodeploy to use this command")
+               },
+       }
+
+       cc.baseBuilderCmd = b.newBuilderBasicCmd(cmd)
+
+       return cc
+}
index dbdf9baf4ad0ad16ed46acaba0c5624012e18263..5e9a7a409585d1c89ce79c5ad6f8f6ddacd56e07 100644 (file)
@@ -11,6 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// +build !nodeploy
+
 package deploy
 
 import (
index f6b5b5785f2832999578f097cc724141a253ddc5..aac0bf354417836839347d34648c22a6538e4e9d 100644 (file)
@@ -11,6 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// +build !nodeploy
+
 package deploy
 
 import (
index cc2b15280a8e89e2f614b14d7fcac9e0931448a5..d4f78011edce6c734b9e498fc9a494a9ca765966 100644 (file)
@@ -11,6 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// +build !nodeploy
+
 package deploy
 
 import (
index c385510fe517ab81d29fff2473a66ba3e72c3939..413b1211b1d0600e251008228b2488623ab76357 100644 (file)
@@ -11,6 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// +build !nodeploy
+
 package deploy
 
 import (
index 6251429ff755e32689a0ef6ecd580c8f596271cd..77bbf5b3d446d0e5005db1e76c34de055fe74e97 100644 (file)
@@ -11,7 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// +build !solaris
+// +build !solaris,!nodeploy
 
 package deploy
 
index 0ae10b5394cececa07bc9798b45d4dde9ee9eb90..987c472caaaa1c09f97f830d0b6b23178757334f 100644 (file)
@@ -11,6 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// +build !nodeploy
+
 package deploy
 
 import (
index be3ce52f0a16c20e6ff01a34adfc804513ddcf6d..9eae10da5ef3548d003f73b91dad8426613a9979 100644 (file)
@@ -11,6 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// +build !nodeploy
+
 package deploy
 
 import (
index 89b7c895d93cb04eb1f88a167b0d61ee6d379cd5..02e49b66e5cc2e803d81edb724f3996756104ad3 100644 (file)
@@ -354,6 +354,7 @@ func buildFlags() []string {
 func buildTags() string {
        // To build the extended Hugo SCSS/SASS enabled version, build with
        // HUGO_BUILD_TAGS=extended mage install etc.
+       // To build without `hugo deploy` for smaller binary, use HUGO_BUILD_TAGS=nodeploy
        if envtags := os.Getenv("HUGO_BUILD_TAGS"); envtags != "" {
                return envtags
        }