Skip to content

Commit 30d51f7

Browse files
authored
Merge pull request #174 from kbst/buildintegratedincontainer
Refactor build automation
2 parents bce1c45 + 4f83386 commit 30d51f7

File tree

13 files changed

+207
-411
lines changed

13 files changed

+207
-411
lines changed

.github/actions/build_artifacts/Dockerfile

-10
This file was deleted.

.github/actions/build_artifacts/action.yaml

-5
This file was deleted.

.github/actions/build_artifacts/dist.py

-72
This file was deleted.

.github/workflows/main.yml

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ jobs:
1414
steps:
1515
- name: 'Checkout'
1616
uses: actions/checkout@v1
17-
18-
- name: Build artifacts
19-
uses: ./.github/actions/build_artifacts
20-
21-
# Docker actions run as root, fix ownership of _dist
22-
- name: Fix owner
23-
run: |
24-
sudo chown -R `id -u`:`id -g` ./quickstart/_dist
17+
18+
- name: 'Build artifacts'
19+
run: make dist
2520

2621
- name: 'Upload artifacts'
2722
uses: actions/upload-artifact@v2

Makefile

+77-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,86 @@
11
_all: dist build
22

3-
GITHUB_REF := $(shell echo "refs/heads/"`git rev-parse --abbrev-ref HEAD`)
4-
GITHUB_SHA := $(shell echo `git rev-parse --verify HEAD^{commit}`)
3+
GIT_REF := $(shell echo "refs/heads/"`git rev-parse --abbrev-ref HEAD`)
4+
GIT_SHA := $(shell echo `git rev-parse --verify HEAD^{commit}`)
55

66
dist:
7-
docker build -t actions_build_artifacts:$(GITHUB_SHA) .github/actions/build_artifacts/
8-
docker run --rm -e GITHUB_REF=$(GITHUB_REF) -e GITHUB_SHA=$(GITHUB_SHA) -v `pwd`/quickstart:/opt/quickstart:z actions_build_artifacts:$(GITHUB_SHA)
7+
rm -rf quickstart/_dist
98

10-
build: dist
11-
docker build --file oci/Dockerfile --progress plain -t kubestack/framework:local-$(GITHUB_SHA) .
9+
docker build \
10+
--build-arg GIT_REF=${GIT_REF} \
11+
--build-arg GIT_SHA=${GIT_SHA} \
12+
--file oci/Dockerfile \
13+
--progress plain \
14+
-t dist-helper:latest \
15+
--target dist-helper \
16+
.
1217

13-
test:
14-
cloud-build-local --substitutions=_KBST_AUTH_AWS=${KBST_AUTH_AWS},_KBST_AUTH_GCLOUD=${KBST_AUTH_GCLOUD},_KBST_AUTH_AZ=${KBST_AUTH_AZ},_GITHUB_REF=$(GITHUB_REF),_GITHUB_SHA=$(GITHUB_SHA) --dryrun=false --config cloudbuild-test.yaml .
18+
docker run \
19+
--detach \
20+
--name dist-helper \
21+
--rm dist-helper:latest \
22+
sleep 600
1523

16-
test-cleanup:
17-
cloud-build-local --substitutions=_KBST_AUTH_AWS=${KBST_AUTH_AWS},_KBST_AUTH_GCLOUD=${KBST_AUTH_GCLOUD},_KBST_AUTH_AZ=${KBST_AUTH_AZ},_GITHUB_REF=$(GITHUB_REF),_GITHUB_SHA=$(GITHUB_SHA) --dryrun=false --config cloudbuild-cleanup.yaml .
24+
docker cp dist-helper:/quickstart/_dist quickstart/_dist
25+
docker stop dist-helper
26+
1827

19-
providers:
20-
cloud-build-local --substitutions=_KBST_AUTH_AWS=${KBST_AUTH_AWS},_KBST_AUTH_GCLOUD=${KBST_AUTH_GCLOUD},_KBST_AUTH_AZ=${KBST_AUTH_AZ},_GITHUB_REF=$(GITHUB_REF),_GITHUB_SHA=$(GITHUB_SHA) --dryrun=false --config cloudbuild-providers.yaml .
28+
build:
29+
docker build \
30+
--build-arg GIT_REF=${GIT_REF} \
31+
--build-arg GIT_SHA=${GIT_SHA} \
32+
--file oci/Dockerfile \
33+
--progress plain \
34+
-t kubestack/framework:local-$(GIT_SHA) \
35+
.
2136

22-
shell: build
23-
docker run -ti --rm -e KBST_AUTH_AWS -e KBST_AUTH_AZ -e KBST_AUTH_GCLOUD -e HOME=/infra/tests/.user -v `pwd`:/infra:z --workdir /infra/tests kubestack/framework:local-$(GITHUB_SHA) bash
37+
validate: .init
38+
docker exec \
39+
test-container-$(GIT_SHA) \
40+
entrypoint terraform validate
41+
42+
test: validate
43+
docker exec \
44+
test-container-$(GIT_SHA) \
45+
entrypoint terraform apply --input=false --auto-approve
46+
47+
cleanup: .init
48+
docker exec \
49+
-ti \
50+
test-container-$(GIT_SHA) \
51+
entrypoint terraform destroy --input=false --auto-approve
52+
$(MAKE) .stop-container
53+
54+
shell: .init
55+
docker exec \
56+
-ti \
57+
test-container-$(GIT_SHA) \
58+
entrypoint bash
59+
60+
.check-container:
61+
docker inspect test-container-${GIT_SHA} > /dev/null || $(MAKE) .run-container
62+
63+
.run-container: build
64+
docker run \
65+
--detach \
66+
--name test-container-${GIT_SHA} \
67+
--rm \
68+
-v `pwd`:/infra:z \
69+
-e KBST_AUTH_AWS \
70+
-e KBST_AUTH_AZ \
71+
-e KBST_AUTH_GCLOUD \
72+
-e HOME=/infra/tests/.user \
73+
--workdir /infra/tests \
74+
kubestack/framework:local-$(GIT_SHA) \
75+
sleep infinity
76+
77+
.stop-container:
78+
docker stop test-container-${GIT_SHA} || true
79+
80+
.init: .check-container
81+
docker exec \
82+
test-container-$(GIT_SHA) \
83+
entrypoint terraform init
84+
docker exec \
85+
test-container-$(GIT_SHA) \
86+
entrypoint terraform workspace select ops

cloudbuild-cleanup.yaml

-76
This file was deleted.

cloudbuild-graph.yaml

-62
This file was deleted.

0 commit comments

Comments
 (0)