diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 00000000..568fdc97 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,87 @@ +name: Dev Build & Deploy + +on: + push: + branches: [dev] + paths: + - 'client/**' + - 'backend/**' + +jobs: + client: + runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, '[client]') + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: set version + run: echo "TAG_VERSION=dev.$(date +'%y-%m-%d').$GITHUB_RUN_NUMBER" >> $GITHUB_ENV + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push client + uses: docker/build-push-action@v2 + with: + context: ./client + file: ./client/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + sayinmehmet47/client-kitapkurdu-1:dev + sayinmehmet47/client-kitapkurdu-1:${{ env.TAG_VERSION }} + - name: Deploy to Kubernetes + run: | + kubectl config set-cluster kubernetes \ + --server="https://rancher.riwi.dev/k8s/clusters/c-m-cp898j4l" + kubectl config set-credentials github-action \ + --token=${{ secrets.KUBE_CONFIG_TOKEN }} + kubectl config set-context default \ + --cluster=kubernetes \ + --user=github-action + kubectl config use-context default + set image deployment/client-deployment client=sayinmehmet47/client-kitapkurdu-1:${{ env.TAG_VERSION }} + env: + KUBECONFIG: kubeconfig + + backend: + runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, '[backend]') + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: set version + run: echo "TAG_VERSION=dev.$(date +'%y-%m-%d').$GITHUB_RUN_NUMBER" >> $GITHUB_ENV + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push backend + uses: docker/build-push-action@v2 + with: + context: ./backend + file: ./backend/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + sayinmehmet47/backend-kitapkurdu-1:dev + sayinmehmet47/backend-kitapkurdu-1:${{ env.TAG_VERSION }} + - name: Deploy to Kubernetes + run: | + kubectl config set-cluster kubernetes \ + --server="https://rancher.riwi.dev/k8s/clusters/c-m-cp898j4l" + kubectl config set-credentials github-action \ + --token=${{ secrets.KUBE_CONFIG_TOKEN }} + kubectl config set-context default \ + --cluster=kubernetes \ + --user=github-action + kubectl config use-context default + kubectl set image deployment/backend-deployment backend diff --git a/infra/k8s-dev/backend-deployment.yaml b/infra/k8s-dev/backend-deployment.yaml index 1bd2963f..0e0d643f 100644 --- a/infra/k8s-dev/backend-deployment.yaml +++ b/infra/k8s-dev/backend-deployment.yaml @@ -19,7 +19,7 @@ spec: spec: containers: - name: kitapkurdu - image: sayinmehmet47/backend-kitapkurdu-1:latest + image: sayinmehmet47/backend-kitapkurdu-1:dev env: - name: MONGO_URI value: ${{ secrets.MONGO_URI_VALUE }} diff --git a/infra/k8s-dev/frontend-deployment.yaml b/infra/k8s-dev/frontend-deployment.yaml index c3e1ddf3..ab95185a 100644 --- a/infra/k8s-dev/frontend-deployment.yaml +++ b/infra/k8s-dev/frontend-deployment.yaml @@ -19,7 +19,7 @@ spec: spec: containers: - name: frontend - image: sayinmehmet47/client-kitapkurdu-1:latest + image: sayinmehmet47/client-kitapkurdu-1:dev env: - name: REACT_APP_LOCAL_API value: https://dev.kitapkurdu.xyz/api