Skip to content

Commit

Permalink
Consolidate Cake build parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
gusztavvargadr committed Jan 14, 2024
1 parent 9fd4a05 commit 7b522d2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 45 deletions.
30 changes: 11 additions & 19 deletions .azure-pipelines/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
demands:
- VSTS_AGENT_CAP_VIRTUALIZATION_PROVIDER -equals ${{ parameters.provider }}

workspace:
clean: all

timeoutInMinutes: 150

variables:
Expand Down Expand Up @@ -41,11 +44,11 @@ jobs:
displayName: Initialize Vagrant
- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target init
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target init
displayName: Init
- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target restore --exclusive
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target restore --exclusive
displayName: Restore
- ${{ if eq(parameters.build, 'native') }}:
Expand All @@ -70,19 +73,19 @@ jobs:
displayName: Download artifacts

- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target build --exclusive
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target build --exclusive
displayName: Build
- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target test --exclusive
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target test --exclusive
displayName: Test
- publish: ./artifacts/${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }}
artifact: ${{ parameters.build }}-build
displayName: Publish artifacts

- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target clean
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target clean
displayName: Clean
condition: always()
Expand All @@ -106,9 +109,6 @@ jobs:
# sudo rm -Rf /usr/local/lib/android
# sudo rm -Rf /usr/local/lib/node_modules
# df -h
curl -Ls https://gist.github.com/gusztavvargadr/1f0d7dddc7f48549368eaaedf19bfe55/raw/provision.sh | sudo CHEF_POLICY="vagrant" bash -s
# sudo apt-get -y install packer
displayName: Initialize agent
- script: |
Expand All @@ -122,15 +122,7 @@ jobs:
displayName: Initialize Packer
- script: |
vagrant --version
vagrant plugin list
vagrant box list
vagrant global-status --prune
displayName: Initialize Vagrant
- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target init
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target init
displayName: Init
- task: DownloadPipelineArtifact@2
Expand All @@ -141,12 +133,12 @@ jobs:
displayName: Download artifacts

- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target publish --exclusive
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target publish --exclusive
displayName: Publish
env:
VAGRANT_CLOUD_TOKEN: $(environment-vagrant-cloud-token)
- script: |
dotnet cake --sample ${{ parameters.sample }} --image ${{ parameters.image }} --provider ${{ parameters.provider }} --build ${{ parameters.build }} --target clean
dotnet cake --configuration ${{ parameters.sample }}/${{ parameters.image }}/${{ parameters.provider }}/${{ parameters.build }} --target clean
displayName: Clean
condition: always()
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
tools

*.lock.json
packer_cache
artifacts
.vagrant
.kitchen
21 changes: 14 additions & 7 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
var configuration = Argument("configuration", string.Empty);
var target = Argument("target", "default");

var sample = Argument<string>("sample");
var image = Argument<string>("image");
var provider = Argument<string>("provider");
var build = Argument<string>("build");
var author = Argument("author", "gusztavvargadr");
var version = Argument("version", "2312");

var configurationParts = configuration.Split('/', StringSplitOptions.RemoveEmptyEntries);
var sample = configurationParts.ElementAtOrDefault(0) ?? Argument<string>("sample");
var image = configurationParts.ElementAtOrDefault(1) ?? Argument<string>("image");
var provider = configurationParts.ElementAtOrDefault(2) ?? Argument<string>("provider");
var build = configurationParts.ElementAtOrDefault(3) ?? Argument<string>("build");

var platform = (sample.Contains("ubuntu") || sample.Contains("linux")) ? "ubuntu" : "windows";

Expand Down Expand Up @@ -56,13 +61,15 @@ void PackerInit() {
arguments.Append("init");
arguments.Append(platformDirectory);

Packer(arguments.Render());
Packer(arguments);
}

void PackerBuild(string stage) {
var arguments = new ProcessArgumentBuilder();

arguments.Append("build");
arguments.Append($"-var author=\"{author}\"");
arguments.Append($"-var version=\"{version}\"");
arguments.Append($"-var-file=\"images.pkrvars.hcl\"");
arguments.Append($"-var image=\"{image}\"");
arguments.Append($"-var provider=\"{provider}\"");
Expand All @@ -71,10 +78,10 @@ void PackerBuild(string stage) {
arguments.Append("-force");
arguments.Append(platformDirectory);

Packer(arguments.Render());
Packer(arguments);
}

void Packer(string arguments) {
void Packer(ProcessArgumentBuilder arguments) {
var result = StartProcess("packer", new ProcessSettings {
Arguments = arguments,
WorkingDirectory = sampleDirectory
Expand Down
4 changes: 2 additions & 2 deletions samples/core.Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Vagrant.configure("2") do |config|
end

config.vm.provider "vmware_desktop" do |provider, _override|
provider.linked_clone = true
provider.linked_clone = false
end

config.vm.provider "hyperv" do |provider, override|
provider.linked_clone = true
provider.linked_clone = false

override.vm.network "private_network", bridge: hyperv_network_bridge
end
Expand Down
9 changes: 6 additions & 3 deletions src/ubuntu/build.vagrant.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ build {
valid_exit_codes = [0, 1]

env = {
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
VAGRANT_DEFAULT_PROVIDER = "${lookup(local.vagrant_providers, local.image_provider, "")}"
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
}
}

Expand All @@ -117,7 +118,8 @@ build {
max_retries = 1

env = {
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
VAGRANT_DEFAULT_PROVIDER = "${lookup(local.vagrant_providers, local.image_provider, "")}"
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
}
}

Expand All @@ -130,7 +132,8 @@ build {
valid_exit_codes = [0, 1]

env = {
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
VAGRANT_DEFAULT_PROVIDER = "${lookup(local.vagrant_providers, local.image_provider, "")}"
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/ubuntu/core.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ packer {
}

variable "author" {
type = string
default = "gusztavvargadr"
type = string
}

variable "version" {
type = string
default = "2312"
type = string
}

variable "images" {
Expand Down
9 changes: 6 additions & 3 deletions src/windows/build.vagrant.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ build {
valid_exit_codes = [0, 1]

env = {
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
VAGRANT_DEFAULT_PROVIDER = "${lookup(local.vagrant_providers, local.image_provider, "")}"
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
}
}

Expand All @@ -122,7 +123,8 @@ build {
max_retries = 1

env = {
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
VAGRANT_DEFAULT_PROVIDER = "${lookup(local.vagrant_providers, local.image_provider, "")}"
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
}
}

Expand All @@ -135,7 +137,8 @@ build {
valid_exit_codes = [0, 1]

env = {
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
VAGRANT_DEFAULT_PROVIDER = "${lookup(local.vagrant_providers, local.image_provider, "")}"
VAGRANT_BOX_URL = "${local.artifacts_directory}/vagrant/vagrant.box"
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/windows/core.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ packer {
}

variable "author" {
type = string
default = "gusztavvargadr"
type = string
}

variable "version" {
type = string
default = "2312"
type = string
}

variable "images" {
Expand Down

0 comments on commit 7b522d2

Please sign in to comment.