name: CI/CD Pipeline on: push: branches: [main] workflow_dispatch: jobs: build: runs-on: home-server steps: - name: Checkout code uses: actions/checkout@v4 with: clean: false - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} # - name: test # run: | # cd backend # nix-shell -p elixir elixir-ls --run ' # MIX_ENV=test mix deps.get --only test # MIX_ENV=test mix test # ' - name: Build and push backend image run: | cd client docker build \ --build-arg VITE_WS_SERVER=wss://elixir-demo.alexmickelson.guru/socket \ -t alexmickelson/elixir-demo-frontend:$GITHUB_RUN_NUMBER \ . docker push -q alexmickelson/elixir-demo-frontend:$GITHUB_RUN_NUMBER cd ../backend docker build -t alexmickelson/elixir-demo-backend:$GITHUB_RUN_NUMBER . docker push -q alexmickelson/elixir-demo-backend:$GITHUB_RUN_NUMBER - name: cluster setup env: KUBECONFIG_CONTENT: ${{ secrets.KUBE_CONFIG_FILE }} run: | echo "$KUBECONFIG_CONTENT" > /tmp/elixir-kubeconfig.yml export KUBECONFIG=/tmp/elixir-kubeconfig.yml kubectl apply -f kubernetes/0-namespace.yml kubectl get secret backend-secret --namespace alex-elixir-demo || \ kubectl create secret generic backend-secret \ --namespace alex-elixir-demo \ --from-literal=cookie=$(openssl rand -hex 32) \ --from-literal=secret_key_base=$(openssl rand -hex 64) - name: Deploy to Kubernetes env: KUBECONFIG_CONTENT: ${{ secrets.KUBE_CONFIG_FILE }} run: | echo "$KUBECONFIG_CONTENT" > /tmp/elixir-kubeconfig.yml export KUBECONFIG=/tmp/elixir-kubeconfig.yml for file in kubernetes/*.yml; do cat "$file" | envsubst | kubectl apply -f - done