Skip to content

Commit

Permalink
feat(images-dependencies): rename imports to dependencies
Browse files Browse the repository at this point in the history
Rename "imports*" stapel build stages to "dependencies*", do not change stages digests.
  • Loading branch information
distorhead committed Jan 25, 2022
1 parent a8b7737 commit 725fbc9
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 133 deletions.
32 changes: 16 additions & 16 deletions docs/_data/stages.yml
Expand Up @@ -72,11 +72,11 @@ en:
- <task>
cacheVersion: <arbitrary string>
beforeInstallCacheVersion: <arbitrary string>
- &image_artifact_imports_before_install
name: importsBeforeInstall
- &image_artifact_dependencies_before_install
name: dependenciesBeforeInstall
type: "image artifact"
dependencies:
- imports before install
- dependencies before install
references:
- name: "Importing from images and artifacts"
link: "/advanced/building_images_with_stapel/import_directive.html"
Expand Down Expand Up @@ -151,11 +151,11 @@ en:
install:
- <task>
installCacheVersion: <arbitrary string>
- &image_artifact_imports_after_install
name: importsAfterInstall
- &image_artifact_dependencies_after_install
name: dependenciesAfterInstall
type: "image artifact"
dependencies:
- imports after install
- dependencies after install
werf_config: |
import:
- artifact: <artifact name>
Expand Down Expand Up @@ -200,11 +200,11 @@ en:
beforeSetup:
- <task>
beforeSetupCacheVersion: <arbitrary string>
- &image_artifact_imports_before_setup
name: importsBeforeSetup
- &image_artifact_dependencies_before_setup
name: dependenciesBeforeSetup
type: "image artifact"
dependencies:
- imports before setup
- dependencies before setup
werf_config: |
import:
- artifact: <artifact name>
Expand Down Expand Up @@ -257,11 +257,11 @@ en:
references:
- name: "More details: gitArchive, gitCache, gitLatestPatch"
link: "/advanced/building_images_with_stapel/git_directive.html#more-details-gitarchive-gitcache-gitlatestpatch"
- &image_imports_after_setup
name: importsAfterSetup
- &image_dependencies_after_setup
name: dependenciesAfterSetup
type: "image artifact"
dependencies:
- imports after setup
- dependencies after setup
werf_config: |
import:
- artifact: <artifact name>
Expand Down Expand Up @@ -324,7 +324,7 @@ ru:
references:
- name: "Запуск инструкций сборки"
link: "/advanced/building_images_with_stapel/assembly_instructions.html"
- << : *image_artifact_imports_before_install
- << : *image_artifact_dependencies_before_install
references:
- name: "Импорт из артефактов и образов"
link: "/advanced/building_images_with_stapel/import_directive.html"
Expand All @@ -338,7 +338,7 @@ ru:
link: "/advanced/building_images_with_stapel/assembly_instructions.html"
- name: "Зависимость от изменений в git-репозитории"
link: "/advanced/building_images_with_stapel/assembly_instructions.html#зависимость-от-изменений-в-git-репозитории"
- << : *image_artifact_imports_after_install
- << : *image_artifact_dependencies_after_install
references:
- name: "Импорт из артефактов и образов"
link: "/advanced/building_images_with_stapel/import_directive.html"
Expand All @@ -348,7 +348,7 @@ ru:
link: "/advanced/building_images_with_stapel/assembly_instructions.html"
- name: "Зависимость от изменений в git-репозитории"
link: "/advanced/building_images_with_stapel/assembly_instructions.html#зависимость-от-изменений-в-git-репозитории"
- << : *image_artifact_imports_before_setup
- << : *image_artifact_dependencies_before_setup
references:
- name: "Импорт из артефактов и образов"
link: "/advanced/building_images_with_stapel/import_directive.html"
Expand All @@ -362,7 +362,7 @@ ru:
references:
- name: "Подробнее про gitArchive, gitCache, gitLatestPatch"
link: "/advanced/building_images_with_stapel/git_directive.html#подробнее-про-gitarchive-gitcache-gitlatestpatch"
- << : *image_imports_after_setup
- << : *image_dependencies_after_setup
references:
- name: "Импорт из артефактов и образов"
link: "/advanced/building_images_with_stapel/import_directive.html"
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/build_phase.go
Expand Up @@ -578,7 +578,7 @@ func (phase *BuildPhase) calculateStage(ctx context.Context, img *Image, stg sta
return false, nil, err
}

stageDigest, err := calculateDigest(ctx, string(stg.Name()), stageDependencies, phase.StagesIterator.PrevNonEmptyStage, phase.Conveyor)
stageDigest, err := calculateDigest(ctx, stage.GetLegacyCompatibleStageName(stg.Name()), stageDependencies, phase.StagesIterator.PrevNonEmptyStage, phase.Conveyor)
if err != nil {
return false, nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/build/conveyor.go
Expand Up @@ -867,18 +867,18 @@ func initStages(ctx context.Context, image *Image, imageInterfaceConfig config.S

stages = appendIfExist(ctx, stages, stage.GenerateFromStage(imageBaseConfig, image.baseImageRepoId, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateBeforeInstallStage(ctx, imageBaseConfig, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateImportsBeforeInstallStage(imageBaseConfig, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateDependenciesBeforeInstallStage(imageBaseConfig, baseStageOptions))

if gitMappingsExist {
stages = append(stages, stage.NewGitArchiveStage(gitArchiveStageOptions, baseStageOptions))
}

stages = appendIfExist(ctx, stages, stage.GenerateInstallStage(ctx, imageBaseConfig, gitPatchStageOptions, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateImportsAfterInstallStage(imageBaseConfig, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateDependenciesAfterInstallStage(imageBaseConfig, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateBeforeSetupStage(ctx, imageBaseConfig, gitPatchStageOptions, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateImportsBeforeSetupStage(imageBaseConfig, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateDependenciesBeforeSetupStage(imageBaseConfig, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateSetupStage(ctx, imageBaseConfig, gitPatchStageOptions, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateImportsAfterSetupStage(imageBaseConfig, baseStageOptions))
stages = appendIfExist(ctx, stages, stage.GenerateDependenciesAfterSetupStage(imageBaseConfig, baseStageOptions))

if !imageArtifact {
if gitMappingsExist {
Expand Down
50 changes: 33 additions & 17 deletions pkg/build/stage/base.go
Expand Up @@ -21,34 +21,50 @@ import (
type StageName string

const (
From StageName = "from"
BeforeInstall StageName = "beforeInstall"
ImportsBeforeInstall StageName = "importsBeforeInstall"
GitArchive StageName = "gitArchive"
Install StageName = "install"
ImportsAfterInstall StageName = "importsAfterInstall"
BeforeSetup StageName = "beforeSetup"
ImportsBeforeSetup StageName = "importsBeforeSetup"
Setup StageName = "setup"
ImportsAfterSetup StageName = "importsAfterSetup"
GitCache StageName = "gitCache"
GitLatestPatch StageName = "gitLatestPatch"
DockerInstructions StageName = "dockerInstructions"
From StageName = "from"
BeforeInstall StageName = "beforeInstall"
DependenciesBeforeInstall StageName = "dependenciesBeforeInstall"
GitArchive StageName = "gitArchive"
Install StageName = "install"
DependenciesAfterInstall StageName = "dependenciesAfterInstall"
BeforeSetup StageName = "beforeSetup"
DependenciesBeforeSetup StageName = "dependenciesBeforeSetup"
Setup StageName = "setup"
DependenciesAfterSetup StageName = "dependenciesAfterSetup"
GitCache StageName = "gitCache"
GitLatestPatch StageName = "gitLatestPatch"
DockerInstructions StageName = "dockerInstructions"

Dockerfile StageName = "dockerfile"
)

// TODO(compatibility): remove in v1.3
func GetLegacyCompatibleStageName(name StageName) string {
switch name {
case DependenciesBeforeInstall:
return "importsBeforeInstall"
case DependenciesAfterInstall:
return "importsAfterInstall"
case DependenciesBeforeSetup:
return "importsBeforeSetup"
case DependenciesAfterSetup:
return "importsAfterSetup"
default:
return string(name)
}
}

var AllStages = []StageName{
From,
BeforeInstall,
ImportsBeforeInstall,
DependenciesBeforeInstall,
GitArchive,
Install,
ImportsAfterInstall,
DependenciesAfterInstall,
BeforeSetup,
ImportsBeforeSetup,
DependenciesBeforeSetup,
Setup,
ImportsAfterSetup,
DependenciesAfterSetup,
GitCache,
GitLatestPatch,
DockerInstructions,
Expand Down
14 changes: 7 additions & 7 deletions pkg/build/stage/imports.go → pkg/build/stage/dependencies.go
Expand Up @@ -37,20 +37,20 @@ func getImports(imageBaseConfig *config.StapelImageBase, options *getImportsOpti
return imports
}

func newImportsStage(imports []*config.Import, name StageName, baseStageOptions *NewBaseStageOptions) *ImportsStage {
s := &ImportsStage{}
func newDependenciesStage(imports []*config.Import, name StageName, baseStageOptions *NewBaseStageOptions) *DependenciesStage {
s := &DependenciesStage{}
s.imports = imports
s.BaseStage = newBaseStage(name, baseStageOptions)
return s
}

type ImportsStage struct {
type DependenciesStage struct {
*BaseStage

imports []*config.Import
}

func (s *ImportsStage) GetDependencies(ctx context.Context, c Conveyor, _, _ container_runtime.LegacyImageInterface) (string, error) {
func (s *DependenciesStage) GetDependencies(ctx context.Context, c Conveyor, _, _ container_runtime.LegacyImageInterface) (string, error) {
var args []string

for ind, elm := range s.imports {
Expand All @@ -71,7 +71,7 @@ func (s *ImportsStage) GetDependencies(ctx context.Context, c Conveyor, _, _ con
return util.Sha256Hash(args...), nil
}

func (s *ImportsStage) PrepareImage(ctx context.Context, c Conveyor, _, image container_runtime.LegacyImageInterface) error {
func (s *DependenciesStage) PrepareImage(ctx context.Context, c Conveyor, _, image container_runtime.LegacyImageInterface) error {
for _, elm := range s.imports {
sourceImageName := getSourceImageName(elm)
srv, err := c.GetImportServer(ctx, sourceImageName, elm.Stage)
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s *ImportsStage) PrepareImage(ctx context.Context, c Conveyor, _, image co
return nil
}

func (s *ImportsStage) getImportSourceChecksum(ctx context.Context, c Conveyor, importElm *config.Import) (string, error) {
func (s *DependenciesStage) getImportSourceChecksum(ctx context.Context, c Conveyor, importElm *config.Import) (string, error) {
importSourceID := getImportSourceID(c, importElm)
importMetadata, err := c.GetImportMetadata(ctx, s.projectName, importSourceID)
if err != nil {
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *ImportsStage) getImportSourceChecksum(ctx context.Context, c Conveyor,
return importMetadata.Checksum, nil
}

func (s *ImportsStage) generateImportChecksum(ctx context.Context, c Conveyor, importElm *config.Import) (string, error) {
func (s *DependenciesStage) generateImportChecksum(ctx context.Context, c Conveyor, importElm *config.Import) (string, error) {
sourceImageDockerImageName := getSourceImageDockerImageName(c, importElm)
importSourceID := getImportSourceID(c, importElm)

Expand Down
22 changes: 22 additions & 0 deletions pkg/build/stage/dependencies_after_install.go
@@ -0,0 +1,22 @@
package stage

import "github.com/werf/werf/pkg/config"

func GenerateDependenciesAfterInstallStage(imageBaseConfig *config.StapelImageBase, baseStageOptions *NewBaseStageOptions) *DependenciesAfterInstallStage {
imports := getImports(imageBaseConfig, &getImportsOptions{After: Install})
if len(imports) != 0 {
return newDependenciesAfterInstallStage(imports, baseStageOptions)
}

return nil
}

func newDependenciesAfterInstallStage(imports []*config.Import, baseStageOptions *NewBaseStageOptions) *DependenciesAfterInstallStage {
s := &DependenciesAfterInstallStage{}
s.DependenciesStage = newDependenciesStage(imports, DependenciesAfterInstall, baseStageOptions)
return s
}

type DependenciesAfterInstallStage struct {
*DependenciesStage
}
22 changes: 22 additions & 0 deletions pkg/build/stage/dependencies_after_setup.go
@@ -0,0 +1,22 @@
package stage

import "github.com/werf/werf/pkg/config"

func GenerateDependenciesAfterSetupStage(imageBaseConfig *config.StapelImageBase, baseStageOptions *NewBaseStageOptions) *DependenciesAfterSetupStage {
imports := getImports(imageBaseConfig, &getImportsOptions{After: Setup})
if len(imports) != 0 {
return newDependenciesAfterSetupStage(imports, baseStageOptions)
}

return nil
}

func newDependenciesAfterSetupStage(imports []*config.Import, baseStageOptions *NewBaseStageOptions) *DependenciesAfterSetupStage {
s := &DependenciesAfterSetupStage{}
s.DependenciesStage = newDependenciesStage(imports, DependenciesAfterSetup, baseStageOptions)
return s
}

type DependenciesAfterSetupStage struct {
*DependenciesStage
}
22 changes: 22 additions & 0 deletions pkg/build/stage/dependencies_before_install.go
@@ -0,0 +1,22 @@
package stage

import "github.com/werf/werf/pkg/config"

func GenerateDependenciesBeforeInstallStage(imageBaseConfig *config.StapelImageBase, baseStageOptions *NewBaseStageOptions) *DependenciesBeforeInstallStage {
imports := getImports(imageBaseConfig, &getImportsOptions{Before: Install})
if len(imports) != 0 {
return newDependenciesBeforeInstallStage(imports, baseStageOptions)
}

return nil
}

func newDependenciesBeforeInstallStage(imports []*config.Import, baseStageOptions *NewBaseStageOptions) *DependenciesBeforeInstallStage {
s := &DependenciesBeforeInstallStage{}
s.DependenciesStage = newDependenciesStage(imports, DependenciesBeforeInstall, baseStageOptions)
return s
}

type DependenciesBeforeInstallStage struct {
*DependenciesStage
}
22 changes: 22 additions & 0 deletions pkg/build/stage/dependencies_before_setup.go
@@ -0,0 +1,22 @@
package stage

import "github.com/werf/werf/pkg/config"

func GenerateDependenciesBeforeSetupStage(imageBaseConfig *config.StapelImageBase, baseStageOptions *NewBaseStageOptions) *DependenciesBeforeSetupStage {
imports := getImports(imageBaseConfig, &getImportsOptions{Before: Setup})
if len(imports) != 0 {
return newDependenciesBeforeSetupStage(imports, baseStageOptions)
}

return nil
}

func newDependenciesBeforeSetupStage(imports []*config.Import, baseStageOptions *NewBaseStageOptions) *DependenciesBeforeSetupStage {
s := &DependenciesBeforeSetupStage{}
s.DependenciesStage = newDependenciesStage(imports, DependenciesBeforeSetup, baseStageOptions)
return s
}

type DependenciesBeforeSetupStage struct {
*DependenciesStage
}
22 changes: 0 additions & 22 deletions pkg/build/stage/imports_after_install.go

This file was deleted.

22 changes: 0 additions & 22 deletions pkg/build/stage/imports_after_setup.go

This file was deleted.

0 comments on commit 725fbc9

Please sign in to comment.