Refactor tests to run without services and add CI workflow #18
Workflow file for this run
This file contains hidden or 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: CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| pull_request: | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18" | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test | |
| - name: Build Auth service image | |
| run: docker build -t auth-service ./auth | |
| - name: Build Product service image | |
| run: docker build -t product-service ./product | |
| - name: Build Order service image | |
| run: docker build -t order-service ./order | |
| - name: Build API Gateway image | |
| run: docker build -t api-gateway ./api-gateway | |
| push-docker-images: | |
| needs: build-and-test | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push service images | |
| env: | |
| REGISTRY: ${{ secrets.DOCKERHUB_USERNAME }} | |
| GIT_SHA: ${{ github.sha }} | |
| run: | | |
| if [ -z "$REGISTRY" ]; then | |
| echo "Docker Hub username secret is not configured" >&2 | |
| exit 1 | |
| fi | |
| services=(auth product order api-gateway) | |
| for service in "${services[@]}"; do | |
| IMAGE_SHA="$REGISTRY/$service:${GIT_SHA::7}" | |
| IMAGE_LATEST="$REGISTRY/$service:latest" | |
| docker build -t "$IMAGE_SHA" -t "$IMAGE_LATEST" "./$service" | |
| docker push "$IMAGE_SHA" | |
| docker push "$IMAGE_LATEST" | |
| done |