diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..dc1468bfb --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,79 @@ +name: hello-node-ci +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # 1. Checkout repo code + - name: Checkout code + uses: actions/checkout@v3 + + # 2. Setup Node.js (choose version) + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' # Change to your version (e.g., 16, 20) + cache: 'npm' # Enable caching for faster builds + + # 3. Install dependencies + - name: Install dependencies + run: npm install + + # # 4. Run tests + # - name: Run tests + # run: npm test + + # 5. (Optional) Build project + # - name: Build project + # run: npm run build + docker: + runs-on: ubuntu-latest + + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Docker + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + - name: docker push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/hello-node:${{ github.run_id }} + + # updatek8s: + # runs-on: ubuntu-latest + + # needs: docker + + # steps: + # - name: checkout code + # uses: actions/checkout@v4 + # with: + # token: ${{ secrets.GITHUB_TOKEN }} + + # - name: Update tag in kubernetes deployment manifest + # run: | + # sed -i "s|image: .*|image: ${{ secrets.DOCKER_USERNAME }}/node-hello:${{github.run_id}}|" kubernetes/deployment.yaml + + # - name: Commit and push changes + # run: | + # git config --global user.email "abhishek@gmail.com" + # git config --global user.name "Abhishek Veeramalla" + # git add kubernetes/productcatalog/deploy.yaml + # git commit -m "[CI]: Update product catalog image tag" + # git push origin HEAD:main -f diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..21ef28881 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:18 +WORKDIR /usr/src/app +COPY package.json . +RUN npm i +COPY . . +CMD ["node","index.js"] +EXPOSE 3000 diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml new file mode 100644 index 000000000..57f0ac469 --- /dev/null +++ b/kubernetes/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: quadrimuzammil/node-hello:${{github.run_id}} + ports: + - containerPort: 80 diff --git a/node-hello b/node-hello new file mode 160000 index 000000000..987103830 --- /dev/null +++ b/node-hello @@ -0,0 +1 @@ +Subproject commit 987103830720e1b5bcbf6d3894ff5b61bb09b0de