feat(ci/cd): build and push job #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Academy Master Tests | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | |
- name: Build and push Backend image | |
id: build-and-push-backend | |
uses: docker/build-push-action@v4 | |
with: | |
file: ./backend/docker/Dockerfile | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
test-on-docker: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: SetUp Docker | |
uses: docker/setup-buildx-action@v2 | |
- name: Pull The Image | |
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
- name: Run Containers | |
run: make run DETACHED=true | |
- name: Wait for backend container to prepare | |
uses: jakejarvis/wait-action@master | |
with: | |
time: '5s' | |
- name: Run tests | |
run: make test | |
test-on-kubernetes: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up kubectl | |
uses: azure/setup-kubectl@v1 | |
- name: Start minikube | |
uses: medyagh/setup-minikube@master | |
- name: Create ConfigMap | |
run: kubectl create configmap academy-master-env --from-env-file=./backend/.env.local && kubectl create configmap academy-master-env-file --from-file=.env=./backend/.env.local | |
- name: Run Kubernetes Deployments | |
run: kubectl apply -f kubernetes/ | |
- name: Wait for Test Database Deployments | |
run: kubectl wait --for=condition=available --timeout=60s deployment/academy-master-test-postgres-dp | |
- name: Wait for Redis Service | |
run: kubectl wait --for=condition=available --timeout=60s deployment/academy-master-redis-dp | |
- name: Wait for Backend Deployments | |
run: kubectl wait --for=condition=available --timeout=60s deployment/academy-master-backend-dp | |
- name: Run Backend Tests | |
run: kubectl exec -it $(kubectl get pods | grep backend | awk '{print $1}') -- pytest | |
deploy: | |
needs: [ test-on-docker, test-on-kubernetes ] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Fake Deployment | |
run: echo "Deploying the service to the cloud..." |