diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-build-and-push.yml similarity index 100% rename from .github/workflows/docker-image.yml rename to .github/workflows/docker-build-and-push.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml deleted file mode 100644 index cfdf1888..00000000 --- a/.github/workflows/docker-build.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Build Docker image - -on: - pull_request: - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: recursive - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: pokeapi/pokeapi - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - - name: Inspect builder - run: | - echo "Name: ${{ steps.buildx.outputs.name }}" - echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" - echo "Status: ${{ steps.buildx.outputs.status }}" - echo "Flags: ${{ steps.buildx.outputs.flags }}" - echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - - name: Build - id: docker_build - uses: docker/build-push-action@v5 - with: - context: . - file: ./Resources/docker/app/Dockerfile - push: false - platforms: local - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/kustomize.yml b/.github/workflows/docker-k8s.yml similarity index 57% rename from .github/workflows/kustomize.yml rename to .github/workflows/docker-k8s.yml index f26a3cb2..d3fa9eb1 100644 --- a/.github/workflows/kustomize.yml +++ b/.github/workflows/docker-k8s.yml @@ -1,29 +1,45 @@ -name: Deploy Kustomize k8s cluster +name: Build Docker image and create k8s with it on: - workflow_run: - workflows: ["Build and Push Docker image"] - branches: [master, staging] - types: - - completed - schedule: - - cron: '0 0 1 * *' + pull_request: jobs: - create-kustomize-cluster: + docker: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - - name: Lint + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: pokeapi/pokeapi + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + - name: Build + id: docker_build + uses: docker/build-push-action@v5 + with: + context: . + file: ./Resources/docker/app/Dockerfile + push: false + load: true + platforms: local + tags: pokeapi/pokeapi:local + labels: ${{ steps.meta.outputs.labels }} + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + - name: Lint k8s run: (cd Resources/k8s/kustomize && yamllint .) - name: Create k8s Kind Cluster - uses: helm/kind-action@v1.1.0 + uses: helm/kind-action@v1.5.0 with: - version: v0.11.1 + kubectl_version: v1.26.13 - name: Create deployment configuration run: | cp Resources/k8s/kustomize/base/secrets/postgres.env.sample Resources/k8s/kustomize/base/secrets/postgres.env @@ -31,19 +47,19 @@ jobs: cp Resources/k8s/kustomize/base/config/pokeapi.env.sample Resources/k8s/kustomize/base/config/pokeapi.env - name: K8s Apply run: | - if [ ${GITHUB_REF#refs/heads/} = 'master' ]; then make kustomize-apply; else make kustomize-staging-apply; fi + make kustomize-local-apply kubectl proxy & - kubectl describe deployment bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/ - - name: Set default namespace + - name: Set default namespace and print info run: | kubectl config set-context --current --namespace pokeapi + kubectl describe deployment - name: Migrate and build data run: | make k8s-migrate make k8s-build-db bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/pal-park-area/5/ - - name: K8s Apply + - name: K8s wait for job run: | kubectl wait --timeout=120s --for=condition=complete job/load-graphql last_command=$(kubectl get job -o jsonpath='{.status.succeeded}' load-graphql) diff --git a/Makefile b/Makefile index 33d90310..dbd96759 100755 --- a/Makefile +++ b/Makefile @@ -112,9 +112,12 @@ hasura-get-anon-schema: # Dumps GraphQL schema kustomize-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster kubectl apply -k Resources/k8s/kustomize/base/ -kustomize-staging-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster +kustomize-staging-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster using pokeapi/pokeapi:staging kubectl apply -k Resources/k8s/kustomize/staging/ +kustomize-local-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster using the locally available pokeapi/pokeapi:local + kubectl apply -k Resources/k8s/kustomize/local/ + k8s-migrate: # (k8s) Run any pending migrations kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose diff --git a/Resources/k8s/kustomize/local/kustomization.yaml b/Resources/k8s/kustomize/local/kustomization.yaml new file mode 100644 index 00000000..371b3533 --- /dev/null +++ b/Resources/k8s/kustomize/local/kustomization.yaml @@ -0,0 +1,9 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +bases: + - ../base + +images: + - name: pokeapi/pokeapi + newTag: local