Skip to content

Commit

Permalink
windows: move install-calico-windows.ps1 here
Browse files Browse the repository at this point in the history
  • Loading branch information
lmm committed Dec 14, 2021
1 parent f0723f7 commit aab0790
Show file tree
Hide file tree
Showing 3 changed files with 586 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ NODE_CONTAINER_BIN_DIR=./dist/bin/
NODE_CONTAINER_BINARY = $(NODE_CONTAINER_BIN_DIR)/calico-node-$(ARCH)
WINDOWS_BINARY = $(NODE_CONTAINER_BIN_DIR)/calico-node.exe

WINDOWS_GEN_INSTALL_SCRIPT_BIN := hack/bin/gen-install-calico-windows-script

# Base URL of the Calico for Windows installation zip archive.
# This can be overridden for dev releases.
WINDOWS_ARCHIVE_BASE_URL ?= https://docs.projectcalico.org

# This is either "Calico" or "Calico Enterprise"
WINDOWS_INSTALL_SCRIPT_PRODUCT ?= Calico
WINDOWS_INSTALL_SCRIPT := dist/install-calico-windows.ps1

# Variables for the Windows packaging.
# Name of the Windows release ZIP archive.
WINDOWS_ARCHIVE_ROOT := windows-packaging/CalicoWindows
Expand Down Expand Up @@ -159,6 +169,8 @@ clean:
rm -f $(WINDOWS_ARCHIVE_ROOT)/libs/hns/hns.psm1
rm -f $(WINDOWS_ARCHIVE_ROOT)/libs/hns/License.txt
rm -f $(WINDOWS_ARCHIVE_ROOT)/cni/*.exe
rm -f $(WINDOWS_GEN_INSTALL_SCRIPT_BIN)
rm -f $(WINDOWS_INSTALL_SCRIPT)
rm -rf filesystem/included-source
rm -rf dist
rm -rf filesystem/etc/calico/confd/conf.d filesystem/etc/calico/confd/config filesystem/etc/calico/confd/templates
Expand Down Expand Up @@ -520,6 +532,9 @@ endif
$(MAKE) retag-build-images-with-registries RELEASE=true IMAGETAG=$(VERSION)
# Generate the `latest` images.
$(MAKE) retag-build-images-with-registries RELEASE=true IMAGETAG=latest
# Generate the install-calico-windows.ps1 script
$(MAKE) install-calico-windows-script
# Generate the Windows zip archives.
$(MAKE) release-windows-archive

## Produces the Windows ZIP archive for the release.
Expand Down Expand Up @@ -556,6 +571,11 @@ endif
-n $(VERSION) \
$(VERSION) $(WINDOWS_ARCHIVE)

# Update the release with the install-calico-windows.ps1 file too.
ghr -u projectcalico -r node \
-n $(VERSION) \
$(VERSION) $(WINDOWS_INSTALL_SCRIPT)

@echo "Finalize the GitHub release based on the pushed tag."
@echo ""
@echo " https://$(PACKAGE_NAME)/releases/tag/$(VERSION)"
Expand Down Expand Up @@ -642,6 +662,22 @@ build-windows-archive: $(WINDOWS_ARCHIVE_FILES) windows-packaging/nssm-$(WINDOWS
$(WINDOWS_ARCHIVE_BINARY): $(WINDOWS_BINARY)
cp $< $@

# Build the tool to generate the install-calico-windows.ps1 installation script.
$(WINDOWS_GEN_INSTALL_SCRIPT_BIN):
mkdir -p hack/bin
$(DOCKER_RUN) $(CALICO_BUILD) sh -c ' \
$(GIT_CONFIG_SSH) \
go build -o $@ ./hack/gen-install-calico-windows-script'

# Generate the install-calico-windows.ps1 installation script.
# For dev releases, override WINDOWS_ARCHIVE_BASE_URL.
install-calico-windows-script $(WINDOWS_INSTALL_SCRIPT): $(WINDOWS_GEN_INSTALL_SCRIPT_BIN)
$(WINDOWS_GEN_INSTALL_SCRIPT_BIN) \
-product "$(WINDOWS_INSTALL_SCRIPT_PRODUCT)" \
-version $(GIT_VERSION) \
-templatePath windows-packaging/install-calico-windows.ps1.tpl \
-baseUrl $(WINDOWS_ARCHIVE_BASE_URL) \
-debug true > $(WINDOWS_INSTALL_SCRIPT)

###############################################################################
# Utilities
Expand Down
111 changes: 111 additions & 0 deletions hack/gen-install-calico-windows-script/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) 2021 Tigera, Inc. 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.

package main

import (
"errors"
"flag"
"fmt"
"log"
"os"
"text/template"
)

type install struct {
Product string `json:"product"`
ProductName string `json:"productName"`
Version string `json:"version"`
BaseUrl string `json:"baseUrl"`
RootDir string `json:"rootDir"`
ZipFileName string `json:"zipFileName"`
}

func newInstall(product, version, baseUrl string) (install, error) {
data := install{
Product: product,
Version: version,
BaseUrl: baseUrl,
}
var productName, rootDir, zipFileName string

if product == "Calico" {
productName = "Calico for Windows"
rootDir = "CalicoWindows"
zipFileName = "calico-windows.zip"
} else if product == "Calico Enterprise" {
productName = "Tigera Calico for Windows"
rootDir = "TigeraCalico"
zipFileName = "tigera-calico-windows.zip"
} else {
return data, fmt.Errorf("invalid product: %v", product)
}

data.ProductName = productName
data.RootDir = rootDir
data.ZipFileName = zipFileName
return data, nil
}

var (
product string
version string
templatePath string
baseUrl string
debug bool
)

func main() {
flag.StringVar(&product, "product", "", `product to generate install script for. either "Calico" or "Calico Enterprise"`)
flag.StringVar(&version, "version", "", `version`)
flag.StringVar(&templatePath, "templatePath", "", `path to the template for the installation script`)
flag.StringVar(&baseUrl, "baseUrl", "", `URL where the installation zip file will be hosted. Required for Calico only`)
flag.BoolVar(&debug, "debug", false, `enable debug logging`)
flag.Parse()

if debug {
log.Printf("product: %v, version: %v, templatePath: %v, baseUrl: %v", product, version, templatePath, baseUrl)
}

if product == "" || version == "" || templatePath == "" {
log.Fatalf("product, version, templatePath, and baseUrl must all be specified")
}

if product == "Calico" && baseUrl == "" {
log.Fatalf("baseUrl is required for Calico")
}

if _, err := os.Stat(templatePath); errors.Is(err, os.ErrNotExist) {
log.Fatalf("templatePath %v does not exist", templatePath)
}

data, err := newInstall(product, version, baseUrl)
if err != nil {
log.Fatalf("error generating installation script data: %v", err)
}

if debug {
log.Printf("using install data: %+v", data)
}

t, err := template.ParseFiles(templatePath)
if err != nil {
log.Fatalf("error parsing template: %v", err)
}

err = t.Execute(os.Stdout, data)
if err != nil {
log.Fatalf("error rendering template: %v", err)
}
}
Loading

0 comments on commit aab0790

Please sign in to comment.