Skip to content

Commit

Permalink
Merge pull request #49 from pauldotyu/refactor-for-azure
Browse files Browse the repository at this point in the history
Refactor for azure
  • Loading branch information
chzbrgr71 authored Aug 8, 2023
2 parents 1145567 + f1f92ab commit 8203441
Show file tree
Hide file tree
Showing 31 changed files with 651 additions and 361 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.env
rabbitmq_enabled_plugins
10 changes: 7 additions & 3 deletions .github/workflows/package-ai-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=ai-service" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-makeline-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=makeline-service" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-order-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=order-service" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-product-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=product-service" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-store-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=store-admin" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-store-front.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=store-front" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-virtual-customer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=virtual-customer" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-virtual-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:

workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
publish-container-image:

Expand All @@ -18,7 +22,7 @@ jobs:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/azure-samples/aks-store-demo" >> "$GITHUB_OUTPUT"
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=virtual-worker" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
Expand All @@ -41,8 +45,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
Expand Down
103 changes: 103 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
IMAGE_VERSION ?= 0.0.1-beta

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: all
all: build load kustomize deploy ## Build all container images, load images into kind cluster, and deploy to kind cluster

##@ Build images

.PHONY: build
build: ./src/order-service/Dockerfile \
./src/makeline-service/Dockerfile \
./src/product-service/Dockerfile \
./src/store-front/Dockerfile \
./src/store-admin/Dockerfile \
./src/virtual-customer/Dockerfile \
./src/virtual-worker/Dockerfile \
## Build all images
docker build -t order-service:$(IMAGE_VERSION) ./src/order-service
docker build -t makeline-service:$(IMAGE_VERSION) ./src/makeline-service
docker build -t product-service:$(IMAGE_VERSION) ./src/product-service
docker build -t store-front:$(IMAGE_VERSION) ./src/store-front
docker build -t store-admin:$(IMAGE_VERSION) ./src/store-admin
docker build -t virtual-customer:$(IMAGE_VERSION) ./src/virtual-customer
docker build -t virtual-worker:$(IMAGE_VERSION) ./src/virtual-worker

##@ Deploy to kind cluster

.PHONY: load
load: build kind ## Load all locally built containers into kind cluster
$(KIND) load docker-image \
order-service:$(IMAGE_VERSION) \
makeline-service:$(IMAGE_VERSION) \
product-service:$(IMAGE_VERSION) \
store-front:$(IMAGE_VERSION) \
store-admin:$(IMAGE_VERSION) \
virtual-customer:$(IMAGE_VERSION) \
virtual-worker:$(IMAGE_VERSION)

.PHONY: manifest ## Create kustomization.yaml and set image versions to locally built images
manifest: kustomize aks-store-all-in-one.yaml
$(KUSTOMIZE) create --resources aks-store-all-in-one.yaml
$(KUSTOMIZE) edit set image ghcr.io/azure-samples/aks-store-demo/order-service=order-service:$(IMAGE_VERSION)
$(KUSTOMIZE) edit set image ghcr.io/azure-samples/aks-store-demo/makeline-service=makeline-service:$(IMAGE_VERSION)
$(KUSTOMIZE) edit set image ghcr.io/azure-samples/aks-store-demo/product-service=product-service:$(IMAGE_VERSION)
$(KUSTOMIZE) edit set image ghcr.io/azure-samples/aks-store-demo/store-front=store-front:$(IMAGE_VERSION)
$(KUSTOMIZE) edit set image ghcr.io/azure-samples/aks-store-demo/store-admin=store-admin:$(IMAGE_VERSION)
$(KUSTOMIZE) edit set image ghcr.io/azure-samples/aks-store-demo/virtual-customer=virtual-customer:$(IMAGE_VERSION)
$(KUSTOMIZE) edit set image ghcr.io/azure-samples/aks-store-demo/virtual-worker=virtual-worker:$(IMAGE_VERSION)

.PHONY: deploy
deploy: manifest ## Deploy to cluster
kubectl apply -k .

.PHONY: clean
clean: ## Delete kind cluster and kustomization.yaml
@if [ `kind get clusters | wc -l` -gt 0 ]; then \
kind delete cluster; \
fi
@rm -f kustomization.yaml
@rm -rf $(LOCALBIN)

##@ Build Dependencies

LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

# tools
KUSTOMIZE ?= $(LOCALBIN)/kustomize
ENVTEST ?= $(LOCALBIN)/setup-envtest
KIND ?= $(LOCALBIN)/kind

# tool versions
KUSTOMIZE_VERSION ?= v5.1.1
KIND_VERSION ?= v0.20.0

# kustomize
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: kind
kind: $(KIND) ## Download kind locally if necessary and create a new cluster. If wrong version is installed, it will be overwritten.
$(KIND): $(LOCALBIN)
test -s $(LOCALBIN)/kind && $(LOCALBIN)/kind --version | grep -q $(KIND_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION)
@if [ `$(KIND) get clusters | wc -l` -eq 0 ]; then \
$(KIND) create cluster; \
fi
Loading

0 comments on commit 8203441

Please sign in to comment.