Skip to content

Commit

Permalink
Merge pull request #1032 from aziontech/dev
Browse files Browse the repository at this point in the history
Deploy to Production - 2024/10/17
  • Loading branch information
PatrickMenoti authored Dec 18, 2024
2 parents f917c82 + 845cffc commit 478afb6
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 72 deletions.
120 changes: 63 additions & 57 deletions .github/workflows/deploy_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ jobs:
AUTH_URL: https://sso.azion.com/api
TEMPLATE_BRANCH: main
SEGMENT_KEY: Irg63QfdvWpoANAVeCBEwfxXBKvoSSzt
CHOCOLATEY_TOKEN: ${{ secrets.CHOCO_TOKEN }}


bump_formula:
runs-on: ubuntu-latest
Expand All @@ -102,63 +104,67 @@ jobs:
formula: azion
tag: ${{needs.build.outputs.binver}}

publish-choco-package:
runs-on: windows-latest
needs: bump_formula
steps:
# Step 1: Check out the code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Chocolatey
- name: Set up Chocolatey
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
# Step 3: Update version in nuspec
- name: Update version in azion.nuspec
run: |
$version = '${{ needs.build.outputs.binver }}'
# Update the version tag in azion.nuspec
(Get-Content chocolatey/azion.nuspec) -replace '<version>.*</version>', "<version>$version</version>" | Set-Content chocolatey/azion.nuspec
shell: pwsh

# Step 4: Download the Azion executable
- name: Download Azion executable
run: |
$toolsDir = "$(Resolve-Path .\chocolatey\tools)"
New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null
$outputFile = Join-Path $toolsDir 'azion.exe'
$url = 'http://downloads.azion.com/windows/x86_64/azion'
Invoke-WebRequest -Uri $url -OutFile $outputFile
shell: pwsh

# Step 5: Calculate checksum
- name: Calculate checksum
id: calculate-checksum
run: |
$outputFile = "$(Resolve-Path .\chocolatey\tools\azion.exe)"
$checksum = (Get-FileHash -Path $outputFile -Algorithm SHA256).Hash
echo "::set-output name=checksum::$checksum"
shell: pwsh

# Step 6: Replace checksum in chocolateyinstall.ps1
- name: Replace checksum in chocolateyinstall.ps1
run: |
(Get-Content .\chocolatey\tools\chocolateyinstall.ps1) -replace '{{CHECKSUM}}', '${{ steps.calculate-checksum.outputs.checksum }}' | Set-Content .\chocolatey\tools\chocolateyinstall.ps1
shell: pwsh

# Step 7: Pack and push the Chocolatey package
- name: Publish Chocolatey package
env:
CHOCO_API_KEY: ${{ secrets.CHOCO_TOKEN }}
run: |
# Ensure that the Chocolatey package is packed and pushed correctly
choco pack chocolatey/azion.nuspec
choco push chocolatey/azion.${{ needs.build.outputs.binver }}.nupkg --source https://push.chocolatey.org/ --api-key $env:CHOCO_API_KEY
shell: pwsh
# publish-choco-package:
# runs-on: windows-latest
# needs: build
# steps:
# # Step 1: Check out the code
# - name: Checkout code
# uses: actions/checkout@v3

# # Step 2: Set up Chocolatey
# - name: Set up Chocolatey
# run: |
# Set-ExecutionPolicy Bypass -Scope Process -Force
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression

# # Step 3: Update version in azion.nuspec
# - name: Update version in azion.nuspec
# run: |
# $version = '${{ needs.build.outputs.binver }}'
# if (-Not $version) {
# Write-Error "Version is not defined! Check the output from bump_formula."
# exit 1
# }
# Write-Host "Updating nuspec version to $version"
# (Get-Content chocolatey/azion.nuspec) -replace '<version>.*</version>', "<version>$version</version>" | Set-Content chocolatey/azion.nuspec
# shell: pwsh

# # Step 4: Download the Azion executable
# - name: Download Azion executable
# run: |
# $toolsDir = "$(Resolve-Path .\chocolatey\tools)"
# New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null
# $outputFile = Join-Path $toolsDir 'azion.exe'
# $url = 'http://downloads.azion.com/windows/x86_64/azion'
# Invoke-WebRequest -Uri $url -OutFile $outputFile
# shell: pwsh

# # Step 5: Calculate checksum
# - name: Calculate checksum
# id: calculate-checksum
# run: |
# $outputFile = "$(Resolve-Path .\chocolatey\tools\azion.exe)"
# $checksum = (Get-FileHash -Path $outputFile -Algorithm SHA256).Hash
# echo "::set-output name=checksum::$checksum"
# shell: pwsh

# # Step 6: Replace checksum in chocolateyinstall.ps1
# - name: Replace checksum in chocolateyinstall.ps1
# run: |
# (Get-Content .\chocolatey\tools\chocolateyinstall.ps1) -replace '{{CHECKSUM}}', '${{ steps.calculate-checksum.outputs.checksum }}' | Set-Content .\chocolatey\tools\chocolateyinstall.ps1
# shell: pwsh

# # Step 7: Pack and push the Chocolatey package
# - name: Publish Chocolatey package
# env:
# CHOCO_API_KEY: ${{ secrets.CHOCO_TOKEN }}
# run: |
# # Ensure that the Chocolatey package is packed and pushed correctly
# choco pack chocolatey/azion.nuspec
# choco push chocolatey/azion.${{ needs.build.outputs.binver }}.nupkg --source https://push.chocolatey.org/ --api-key $env:CHOCO_API_KEY
# shell: pwsh

Publish-to-WinGet:
runs-on: windows-latest
Expand Down
58 changes: 55 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project_name: azion

builds:
- env:
id: azion-unit
id: azion-unix
- CGO_ENABLED=0
main: ./cmd/azion
ldflags:
Expand Down Expand Up @@ -40,7 +40,7 @@ builds:
- -X github.com/aziontech/azion-cli/pkg/constants.ApiURL={{ .Env.API_URL }}
- -X github.com/aziontech/azion-cli/pkg/constants.StorageApiURL={{ .Env.STORAGE_URL }}
- -X github.com/aziontech/azion-cli/pkg/pkg/cmd/edge_applications/init.TemplateBranch={{ .Env.TEMPLATE_BRANCH }}
binary: azion.exe
binary: azion
goos:
- windows
goarch:
Expand All @@ -49,8 +49,21 @@ builds:
- arm64

archives:
- files:
# For non-Windows platforms (Linux, macOS, etc.), include completions and other files
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}_v{{ .Tag }}"
format: tar.gz
files:
- completions/*
if: "{{ .Os != 'windows' }}"

# For Windows, create a zip file containing all the .exe binaries for various architectures
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}_v{{ .Tag }}.zip"
format: zip
files:
- ./dist/azion-windows - CGO_ENABLED=0_windows_386_sse2/azion.exe # 32-bit Windows (386)
- ./dist/azion-windows - CGO_ENABLED=0_windows_amd64_v1/azion.exe # 64-bit Windows (amd64)
- ./dist/azion-windows - CGO_ENABLED=0_windows_arm64_v8.0/azion.exe # ARM64 Windows
if: "{{ .Os == 'windows' }}"

before:
hooks:
Expand Down Expand Up @@ -82,6 +95,45 @@ nfpms:
file_info:
mode: 0644

chocolateys:
- name: azion

package_source_url: https://github.com/aziontech/azion/releases

owners: aziontech

title: azion

authors: PatrickMenoti

project_url: https://github.com/aziontech/azion

url_template: "http://downloads.azion.com/windows/x86_64/azion"

license_url: https://github.com/aziontech/azion/blob/dev/LICENSE

require_license_acceptance: false

project_source_url: https://github.com/aziontech/azion

docs_url: https://www.azion.com/en/documentation/products/azion-cli/overview

bug_tracker_url: https://github.com/aziontech/azion/issues

tags: "azion cli go publish deploy build jamstack"

summary: Use Azion CLI for managing Azion services via command-line.

description: Azion CLI is a user-friendly way to work with the Azion Edge Platform, allowing you to create and manage applications through simple commands.

release_notes: "https://github.com/aziontech/azion/releases/tag/{{ .Version }}"

api_key: "{{ .Env.CHOCOLATEY_TOKEN }}"

source_repo: "https://push.chocolatey.org/"

goamd64: v1

checksum:
name_template: "{{ .ProjectName }}_v{{ .Env.BIN_VERSION }}_checksum"
snapshot:
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type DeployCmd struct {
Unmarshal func(data []byte, v interface{}) error
Interpreter func() *manifestInt.ManifestInterpreter
VersionID func() string
CallScript func(token string, id string, secret string, prefix string, name string, cmd *DeployCmd) (string, error)
CallScript func(token string, id string, secret string, prefix string, name, confDir string, cmd *DeployCmd) (string, error)
OpenBrowser func(f *cmdutil.Factory, urlConsoleDeploy string, cmd *DeployCmd) error
CaptureLogs func(execId string, token string, cmd *DeployCmd) error
CheckToken func(f *cmdutil.Factory) error
Expand Down Expand Up @@ -221,7 +221,7 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error {
return err
}

id, err := cmd.CallScript(settings.Token, settings.S3AccessKey, settings.S3SecreKey, conf.Prefix, settings.S3Bucket, cmd)
id, err := cmd.CallScript(settings.Token, settings.S3AccessKey, settings.S3SecreKey, conf.Prefix, settings.S3Bucket, ProjectConf, cmd)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func MockWriteAzionJsonContent(conf *contracts.AzionApplicationOptions, confConf
}

// MockCallScript mocks the callScript behavior
func MockCallScript(token string, id string, secret string, prefix string, name string, cmd *DeployCmd) (string, error) {
func MockCallScript(token string, id string, secret string, prefix string, name, confDir string, cmd *DeployCmd) (string, error) {
return "mockExecId", nil
}

Expand Down Expand Up @@ -161,7 +161,7 @@ func TestDeploy_Run(t *testing.T) {
cmd.UploadFiles = func(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions, msgs *[]string, pathStatic, bucket string, cmd *DeployCmd, settings token.Settings) error {
return nil
}
cmd.CallScript = func(token string, id string, secret string, prefix string, name string, cmd *DeployCmd) (string, error) {
cmd.CallScript = func(token string, id string, secret string, prefix string, name, confDir string, cmd *DeployCmd) (string, error) {
return "", errors.New("call script failed")
}
cmd.OpenBrowser = MockOpenBrowser
Expand Down Expand Up @@ -313,6 +313,7 @@ func TestCallScript(t *testing.T) {
secret string
prefix string
projectName string
confDir string
resultsResponse string
expectedUUID string
expectedErr bool
Expand All @@ -324,6 +325,7 @@ func TestCallScript(t *testing.T) {
secret: "validSecret",
prefix: "validPrefix",
projectName: "myProject",
confDir: "azion",
resultsResponse: `{"uuid": "12345"}`,
expectedUUID: "12345",
expectedErr: false,
Expand All @@ -335,6 +337,7 @@ func TestCallScript(t *testing.T) {
secret: "validSecret",
prefix: "validPrefix",
projectName: "myProject",
confDir: "azion",
resultsResponse: "",
expectedUUID: "",
expectedErr: true,
Expand Down Expand Up @@ -362,7 +365,7 @@ func TestCallScript(t *testing.T) {
}

// Call the function under test
_, err := cmd.CallScript(tt.token, tt.id, tt.secret, tt.prefix, tt.projectName, cmd)
_, err := cmd.CallScript(tt.token, tt.id, tt.secret, tt.prefix, tt.projectName, tt.confDir, cmd)

// Assert the results
if tt.expectedErr {
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/deploy/scriptrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Response struct {
Start time.Time `json:"start"`
}

func callScript(token, id, secret, prefix, name string, cmd *DeployCmd) (string, error) {
func callScript(token, id, secret, prefix, name, confDir string, cmd *DeployCmd) (string, error) {
logger.Debug("Calling script runner api")
instantiateURL := fmt.Sprintf("%s/api/template-engine/templates/%s/instantiate", DeployURL, ScriptID)

Expand Down Expand Up @@ -52,6 +52,11 @@ func callScript(token, id, secret, prefix, name string, cmd *DeployCmd) (string,
"instantiation_data_path": "envs.[4].value",
"value": token,
},
{
"field": "AZCLI_CONFDIR",
"instantiation_data_path": "envs.[5].value",
"value": confDir,
},
}

// Marshal the payload to JSON
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulcan/vulcan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
const (
currentMajor = 4
installEdgeFunctions = "npx --yes %s edge-functions%s %s"
firstTimeExecuting = "@4.2.0"
firstTimeExecuting = "@4.3.0"
)

var versionVulcan = "@4.2.0"
var versionVulcan = "@4.3.0"

type VulcanPkg struct {
Command func(flags, params string, f *cmdutil.Factory) string
Expand Down
8 changes: 4 additions & 4 deletions pkg/vulcan/vulcan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ func TestCheckVulcanMajor(t *testing.T) {
args: args{
currentVersion: "5.0.0",
},
lastVulcanVer: "4.2.0",
expectedVersion: "@4.2.0",
lastVulcanVer: "4.3.0",
expectedVersion: "@4.3.0",
wantErr: false,
},
{
name: "same major version",
args: args{
currentVersion: "5.0.0",
},
lastVulcanVer: "4.2.0",
expectedVersion: "@4.2.0",
lastVulcanVer: "4.3.0",
expectedVersion: "@4.3.0",
wantErr: false,
},
{
Expand Down

0 comments on commit 478afb6

Please sign in to comment.