Skip to content

Commit 2f96245

Browse files
authored
refactor: move "templates" pkg under "internal/pkg/template" pkg (#2691)
To start using the new ✨ [embed pkg](https://pkg.go.dev/embed) and deprecate our use of packr we need to move all of our templates under the `internal/pkg/template` pkg. This is because unfortunately we can't refer to the current "templates" directory by doing `"../../../templates"`: > Because embed.Files implements fs.FS, it cannot provide access to files with names beginning with .., so files in parent directories are also disallowed entirely, even when the parent directory named by .. does happen to be in the same module. > > golang/go#46056 (comment) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 47f5143 commit 2f96245

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+11
-23
lines changed

Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
BINARY_NAME=copilot
55
PACKAGES=./internal...
6-
SOURCE_CUSTOM_RESOURCES=${PWD}/cf-custom-resources
7-
BUILT_CUSTOM_RESOURCES=${PWD}/templates/custom-resources
8-
GOBIN=${PWD}/bin/tools
6+
ROOT_SRC_DIR=${PWD}
7+
SOURCE_CUSTOM_RESOURCES=${ROOT_SRC_DIR}/cf-custom-resources
8+
TEMPLATES_DIR=${ROOT_SRC_DIR}/internal/pkg/template/templates
9+
BUILT_CUSTOM_RESOURCES=${TEMPLATES_DIR}/custom-resources
10+
GOBIN=${ROOT_SRC_DIR}/bin/tools
911
COVERAGE=coverage.out
1012

1113
DESTINATION=./bin/local/${BINARY_NAME}
@@ -63,9 +65,9 @@ packr-build: tools package-custom-resources
6365
.PHONY: packr-clean
6466
packr-clean: tools package-custom-resources-clean
6567
@echo "Cleaning up static files generated code" &&\
66-
cd templates &&\
68+
cd ${TEMPLATES_DIR} &&\
6769
${GOBIN}/packr2 clean &&\
68-
cd ..\
70+
cd ${ROOT_SRC_DIR} \
6971

7072
.PHONY: test
7173
test: packr-build run-unit-test custom-resource-tests packr-clean
@@ -75,7 +77,7 @@ custom-resource-tests:
7577
@echo "Running custom resource unit tests" &&\
7678
cd ${SOURCE_CUSTOM_RESOURCES} &&\
7779
npm test &&\
78-
cd ..
80+
cd ${ROOT_SRC_DIR}
7981

8082
# Minifies the resources in cf-custom-resources/lib and copies
8183
# those minified assets into templates/custom-resources so that
@@ -85,7 +87,7 @@ package-custom-resources:
8587
@echo "Packaging custom resources to templates/custom-resources" &&\
8688
cd ${SOURCE_CUSTOM_RESOURCES} &&\
8789
npm run package &&\
88-
cd ..
90+
cd ${ROOT_SRC_DIR}
8991

9092
# We only need the minified custom resources during building. After
9193
# they're packed, we can remove them.

cf-custom-resources/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"lint": "eslint lib",
1414
"build+test+package": "npm run build+test",
1515
"build+test": "npm run build && npm test",
16-
"package": "minify lib -d ../templates/custom-resources --builtIns false"
16+
"package": "minify lib -d ../internal/pkg/template/templates/custom-resources --builtIns false"
1717
},
1818
"keywords": [],
1919
"author": {

internal/pkg/deploy/cloudformation/app_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"github.com/aws/copilot-cli/internal/pkg/deploy"
1818
"github.com/aws/copilot-cli/internal/pkg/deploy/cloudformation/mocks"
1919
"github.com/aws/copilot-cli/internal/pkg/deploy/cloudformation/stack"
20-
"github.com/aws/copilot-cli/templates"
21-
"github.com/gobuffalo/packd"
2220
"github.com/golang/mock/gomock"
2321
"github.com/stretchr/testify/require"
2422
"gopkg.in/yaml.v3"
@@ -100,7 +98,6 @@ func TestCloudFormation_DeployApp(t *testing.T) {
10098
cf := CloudFormation{
10199
cfnClient: tc.mockStack(ctrl),
102100
appStackSet: tc.mockStackSet(t, ctrl),
103-
box: templates.Box(),
104101
region: tc.region,
105102
}
106103

@@ -343,7 +340,6 @@ func TestCloudFormation_AddEnvToApp(t *testing.T) {
343340
defer ctrl.Finish()
344341
cf := CloudFormation{
345342
appStackSet: tc.mockStackSet(t, ctrl),
346-
box: templates.Box(),
347343
region: "us-west-2",
348344
}
349345
got := cf.AddEnvToApp(&AddEnvToAppOpts{
@@ -411,7 +407,6 @@ func TestCloudFormation_AddPipelineResourcesToApp(t *testing.T) {
411407
defer ctrl.Finish()
412408
cf := CloudFormation{
413409
appStackSet: tc.mockStackSet(t, ctrl),
414-
box: templates.Box(),
415410
}
416411
getRegionFromClient = tc.getRegionFromClient
417412

@@ -512,7 +507,6 @@ func TestCloudFormation_AddServiceToApp(t *testing.T) {
512507
defer ctrl.Finish()
513508
cf := CloudFormation{
514509
appStackSet: tc.mockStackSet(t, ctrl),
515-
box: templates.Box(),
516510
region: "us-west-2",
517511
}
518512

@@ -571,7 +565,6 @@ func TestCloudFormation_RemoveServiceFromApp(t *testing.T) {
571565
defer ctrl.Finish()
572566
cf := CloudFormation{
573567
appStackSet: tc.mockStackSet(t, ctrl),
574-
box: templates.Box(),
575568
region: "us-west-2",
576569
}
577570

@@ -662,7 +655,6 @@ func TestCloudFormation_GetRegionalAppResources(t *testing.T) {
662655
return tc.createRegionalMockClient(ctrl)
663656
},
664657
appStackSet: tc.mockStackSet(t, ctrl),
665-
box: packd.NewMemoryBox(),
666658
}
667659

668660
// WHEN
@@ -748,7 +740,6 @@ func TestCloudFormation_GetAppResourcesByRegion(t *testing.T) {
748740
return tc.createRegionalMockClient(ctrl)
749741
},
750742
appStackSet: tc.mockStackSet(t, ctrl),
751-
box: packd.NewMemoryBox(),
752743
}
753744

754745
// WHEN
@@ -844,7 +835,6 @@ func TestCloudFormation_DelegateDNSPermissions(t *testing.T) {
844835
defer ctrl.Finish()
845836
cf := CloudFormation{
846837
cfnClient: tc.createMock(ctrl),
847-
box: templates.Box(),
848838
}
849839

850840
// WHEN

internal/pkg/deploy/cloudformation/cloudformation.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import (
2828
"github.com/aws/copilot-cli/internal/pkg/stream"
2929
"github.com/aws/copilot-cli/internal/pkg/term/log"
3030
"github.com/aws/copilot-cli/internal/pkg/term/progress"
31-
"github.com/aws/copilot-cli/templates"
32-
"github.com/gobuffalo/packd"
3331
"golang.org/x/sync/errgroup"
3432
)
3533

@@ -108,7 +106,6 @@ type CloudFormation struct {
108106
ecsClient ecsClient
109107
regionalClient func(region string) cfnClient
110108
appStackSet stackSetClient
111-
box packd.Box
112109
s3Client s3Client
113110
region string
114111
}
@@ -126,7 +123,6 @@ func New(sess *session.Session) CloudFormation {
126123
}))
127124
},
128125
appStackSet: stackset.New(sess),
129-
box: templates.Box(),
130126
s3Client: s3.New(sess),
131127
region: aws.StringValue(sess.Config.Region),
132128
}

internal/pkg/template/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"text/template"
1414

1515
"github.com/aws/copilot-cli/internal/pkg/aws/s3"
16-
"github.com/aws/copilot-cli/templates"
16+
"github.com/aws/copilot-cli/internal/pkg/template/templates"
1717
"github.com/gobuffalo/packd"
1818
)
1919

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)