diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..18d23a7 --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,18 @@ +# Github Actions + +This folder contains the definition of a Github action used to build and push the image into a registry and also to setup a minikube cluster to test the deployment of the helm chart. + +## setup +In order to use Github Actions for your repository it's necessary to setup two secrets and two environment variables in your project settings. + +1. In Github go into your repository then click `Settings` +2. On left side you can see a section called `Security` +3. Click on `Secrets and variables` -> `Actions` +4. Add the secret `REGISTRY_ROBOT_PASSWORD` (the password used to access to the image registry) +5. Add the secret `REGISTRY_ROBOT_USERNAME` (the username used to access to the image registry) +6. Add the variable `REGISTRY_ADDRESS` (the address of the image registry, could be quay.io or docker.io) +7. Add the variable `REGISTRY_USERNAME` (the username used in the image registry) + +Once these variables have been setted it is possible to run the action and see the output + +**NOTE**: the action build and push the image with the default tag `latest` \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..b6025a7 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,66 @@ +name: Docker Image CI + +on: + push: + branches: [ "master", "feat/pipeline-improvement" ] + pull_request: + branches: [ "master" ] + +env: + IMAGE_TAG: ${{ github.event_name == 'push' && 'latest' || 'latest-pull-request' }} + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - name: Login to Quay.io + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.REGISTRY_ROBOT_USERNAME }} + password: ${{ secrets.REGISTRY_ROBOT_PASSWORD }} + + - uses: actions/checkout@v4 + + - name: Build the Docker image + run: | + docker build . --file Dockerfile --tag ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_USERNAME }}/kubeinvaders:${{ env.IMAGE_TAG }} + docker push ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_USERNAME }}/kubeinvaders:${{ env.IMAGE_TAG }} + + - name: Start minikube + uses: medyagh/setup-minikube@latest + with: + driver: docker + kubernetes-version: v1.26.3 + cpus: 4 + memory: 2048m + + - name: Try the cluster! + run: kubectl get pods -A + + - name: Deploy example + run: | + kubectl apply -f minikube-setup/manifests --wait=true + kubectl get all -n "ns-1" + + - name: Deploy with helm + run: | + helm upgrade --install \ + kubeinvaders \ + -n kubeinvaders \ + --create-namespace \ + helm-charts/kubeinvaders \ + --set ingress.enabled=true \ + --set deployment.image.tag=latest \ + --set ingress.hostName=kubeinvaders.local \ + --set-string config.target_namespace="ns-1" \ + --set deployment.image.repository=${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_USERNAME }} + + - name: Check if service is available + run: | + kubectl get all -n kubeinvaders + +