|
| 1 | +.PHONY: all dev clean mongo-shell |
| 2 | + |
| 3 | +all: dev |
| 4 | + |
| 5 | +dev: |
| 6 | + @echo "Creating k3d cluster..." |
| 7 | + -@k3d cluster create a50passos -p "8080:80@loadbalancer" --registry-create k3d-a50passos-registry:10000 --wait |
| 8 | + |
| 9 | + @echo "Starting local database..." |
| 10 | + -@docker run -d --name mongodb -p 27017:27017 mongo |
| 11 | + |
| 12 | + @echo "Creating namespace..." |
| 13 | + @kubectl apply -f local/namespace.yml |
| 14 | + |
| 15 | + @echo "Creating secrets..." |
| 16 | + -@kubectl create secret generic a50passos-secrets -n a50passos \ |
| 17 | + --from-literal=DATABASE=mongodb://host.docker.internal:27017/a50passos \ |
| 18 | + --from-literal=SESSION_SECRET=SECRET |
| 19 | + |
| 20 | + @echo "Building website image..." |
| 21 | + @docker build --pull --no-cache -t fraguinha/a50passos.com:latest src/website |
| 22 | + |
| 23 | + @echo "Building assets image..." |
| 24 | + @docker build --pull --no-cache -t fraguinha/a50passos.com-assets:latest -f src/website/Dockerfile.assets . |
| 25 | + |
| 26 | + @echo "Tagging website image..." |
| 27 | + @docker tag fraguinha/a50passos.com localhost:10000/fraguinha/a50passos.com:latest |
| 28 | + |
| 29 | + @echo "Tagging assets image..." |
| 30 | + @docker tag fraguinha/a50passos.com-assets localhost:10000/fraguinha/a50passos.com-assets:latest |
| 31 | + |
| 32 | + @echo "Pushing website image..." |
| 33 | + @docker push localhost:10000/fraguinha/a50passos.com:latest |
| 34 | + |
| 35 | + @echo "Pushing assets image..." |
| 36 | + @docker push localhost:10000/fraguinha/a50passos.com-assets:latest |
| 37 | + |
| 38 | + @echo "Capturing website image digest..."; \ |
| 39 | + WEBSITE_SHA=$$(docker inspect --format='{{index .RepoDigests 0}}' fraguinha/a50passos.com:latest | cut -d'@' -f2); \ |
| 40 | + echo "Website SHA: $$WEBSITE_SHA"; \ |
| 41 | + \ |
| 42 | + echo "Capturing assets image digest..."; \ |
| 43 | + ASSETS_SHA=$$(docker inspect --format='{{index .RepoDigests 0}}' fraguinha/a50passos.com-assets:latest | cut -d'@' -f2); \ |
| 44 | + echo "Assets SHA: $$ASSETS_SHA"; \ |
| 45 | + \ |
| 46 | + echo "Patching kubernetes manifests with SHA digests..."; \ |
| 47 | + sed -i '' "s|a50passos.com:latest|a50passos.com:latest@$$WEBSITE_SHA|g" local/website.yml; \ |
| 48 | + sed -i '' "s|a50passos.com-assets:latest|a50passos.com-assets:latest@$$ASSETS_SHA|g" local/website.yml; \ |
| 49 | + \ |
| 50 | + echo "Applying kubernetes manifests..."; \ |
| 51 | + kubectl apply -k local/ |
| 52 | + |
| 53 | + @echo "Rolling out deployments..." |
| 54 | + @kubectl rollout restart deployment/website -n a50passos |
| 55 | + |
| 56 | + @echo "Waiting for deployments to be successful..." |
| 57 | + @kubectl rollout status deployment/website -n a50passos |
| 58 | + |
| 59 | + @echo "Restoring kubernetes manifests..." |
| 60 | + @sed -i '' "s|@sha256:.*||g" local/website.yml |
| 61 | + |
| 62 | + @echo "You can now access the application at http://localhost:8080" |
| 63 | + |
| 64 | +clean: |
| 65 | + @echo "Cleaning docker resources..." |
| 66 | + @docker stop $$(docker ps -aq) |
| 67 | + @docker container prune -f |
| 68 | + @docker image prune -f |
| 69 | + @docker volume prune -af |
| 70 | + @docker network prune -f |
| 71 | + |
| 72 | +mongo-shell: |
| 73 | + @echo "Connecting to MongoDB shell..." |
| 74 | + @docker exec -it mongodb mongosh |
0 commit comments