diff --git a/.github/actions/registry-login/action.yml b/.github/actions/registry-login/action.yml new file mode 100644 index 000000000..89e14bc1c --- /dev/null +++ b/.github/actions/registry-login/action.yml @@ -0,0 +1,44 @@ +name: "Container Registry Login" +description: "Reusable action for logging in to container registries using workflow inputs" +inputs: + registry_provider: + required: false + gcp_service_account_key: + required: false + registry_name: + required: false + registry_url: + required: false + registry_username: + required: false + registry_password: + required: false + github_token: + required: false +runs: + using: "composite" + steps: + - run: | + case "${{ inputs.registry_provider }}" in + "gcp") + echo "Using Google Container Registry" + echo "${{ inputs.gcp_service_account_key }}" | base64 --decode > $HOME/gcloud-key.json + gcloud auth activate-service-account --key-file=$HOME/gcloud-key.json + gcloud auth configure-docker ${{ inputs.registry_name }} + REGISTRY_URL=$(echo "${{ inputs.registry_url }}" | tr '[:upper:]' '[:lower:]') + ;; + "azure" | "dockerhub") + echo "Logging in to Container Registry" + echo "${{ inputs.registry_password }}" | docker login ${{ inputs.registry_name }} \ + --username ${{ inputs.registry_username }} --password-stdin + REGISTRY_URL=$(echo "${{ inputs.registry_url }}" | tr '[:upper:]' '[:lower:]') + ;; + *) + echo "Using GitHub Container Registry (GHCR)" + REPO_NAME_LOWERCASE=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]') + echo "${{ inputs.github_token }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + REGISTRY_URL="ghcr.io/$REPO_NAME_LOWERCASE" + ;; + esac + echo "REGISTRY_URL=${REGISTRY_URL}" >> $GITHUB_ENV + shell: bash \ No newline at end of file diff --git a/.github/workflows/content-service.yml b/.github/workflows/content-service.yml new file mode 100644 index 000000000..70274bef9 --- /dev/null +++ b/.github/workflows/content-service.yml @@ -0,0 +1,68 @@ +name: Build and Push Content Service Image + +on: + push: + tags: + - '*' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout the code + - name: Checkout code + uses: actions/checkout@v2 + + # Step 2: Set up JDK 11 and Maven + - name: Set up JDK 11 and Maven + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + cache: 'maven' + + # Step 3: Set up Login to Docker registry + - name: Registry Login + uses: ./.github/actions/registry-login + with: + registry_provider: ${{ vars.REGISTRY_PROVIDER }} + gcp_service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + registry_name: ${{ secrets.REGISTRY_NAME }} + registry_url: ${{ secrets.REGISTRY_URL }} + registry_username: ${{ secrets.REGISTRY_USERNAME }} + registry_password: ${{ secrets.REGISTRY_PASSWORD }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + # Step 4: Build the project + - name: Build Content Service + run: | + mvn clean install -DskipTests=true \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + + # Step 5: Package the project + - name: Package Content Service + run: | + cd content-api + mvn play2:dist -pl content-service \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + + # Step 6: Build Docker image + - name: Build Docker Image + run: | + IMAGE_NAME="content-service" + IMAGE_TAG=$(echo "${{ github.ref_name }}_$(echo $GITHUB_SHA | cut -c1-7)" | tr '[:upper:]' '[:lower:]') + docker build -f build/content-service/Dockerfile -t $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG} . + + echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV + + # Step 7: Push Docker Image + - name: Push Docker Image + run: | + docker push $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG} + echo "Pushed Docker image: $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG}" \ No newline at end of file diff --git a/.github/workflows/search-service.yml b/.github/workflows/search-service.yml new file mode 100644 index 000000000..b97bdd97c --- /dev/null +++ b/.github/workflows/search-service.yml @@ -0,0 +1,68 @@ +name: Build and Push Search Service Image + +on: + push: + tags: + - '*' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout the code + - name: Checkout code + uses: actions/checkout@v2 + + # Step 2: Set up JDK 11 and Maven + - name: Set up JDK 11 and Maven + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + cache: 'maven' + + # Step 3: Set up Login to Docker registry + - name: Registry Login + uses: ./.github/actions/registry-login + with: + registry_provider: ${{ vars.REGISTRY_PROVIDER }} + gcp_service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + registry_name: ${{ secrets.REGISTRY_NAME }} + registry_url: ${{ secrets.REGISTRY_URL }} + registry_username: ${{ secrets.REGISTRY_USERNAME }} + registry_password: ${{ secrets.REGISTRY_PASSWORD }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + # Step 4: Build the project + - name: Build Search API Service + run: | + mvn clean install -DskipTests=true \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + + # Step 5: Package the project + - name: Package Search API Service + run: | + cd search-api + mvn play2:dist -pl search-service \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + + # Step 6: Build Docker image + - name: Build Docker Image + run: | + IMAGE_NAME="search-api" + IMAGE_TAG=$(echo "${{ github.ref_name }}_$(echo $GITHUB_SHA | cut -c1-7)" | tr '[:upper:]' '[:lower:]') + docker build -f build/search-service/Dockerfile -t $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG} . + + echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV + + # Step 7: Push Docker Image + - name: Push Docker Image + run: | + docker push $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG} + echo "Pushed Docker image: $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG}" \ No newline at end of file diff --git a/.github/workflows/taxonomy-service.yml b/.github/workflows/taxonomy-service.yml new file mode 100644 index 000000000..b6b608dd1 --- /dev/null +++ b/.github/workflows/taxonomy-service.yml @@ -0,0 +1,68 @@ +name: Build and Push Taxonomy Service Image + +on: + push: + tags: + - '*' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout the code + - name: Checkout code + uses: actions/checkout@v2 + + # Step 2: Set up JDK 11 and Maven + - name: Set up JDK 11 and Maven + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + cache: 'maven' + + # Step 3: Set up Login to Docker registry + - name: Registry Login + uses: ./.github/actions/registry-login + with: + registry_provider: ${{ vars.REGISTRY_PROVIDER }} + gcp_service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + registry_name: ${{ secrets.REGISTRY_NAME }} + registry_url: ${{ secrets.REGISTRY_URL }} + registry_username: ${{ secrets.REGISTRY_USERNAME }} + registry_password: ${{ secrets.REGISTRY_PASSWORD }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + # Step 4: Build the project + - name: Build Taxonomy API Service + run: | + mvn clean install -DskipTests=true \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + + # Step 5: Package the project + - name: Package Taxonomy API Service + run: | + cd taxonomy-api + mvn play2:dist -pl taxonomy-service \ + -DCLOUD_STORE_GROUP_ID=${{ vars.CLOUD_STORE_GROUP_ID }} \ + -DCLOUD_STORE_ARTIFACT_ID=${{ vars.CLOUD_STORE_ARTIFACT_ID }} \ + -DCLOUD_STORE_VERSION=${{ vars.CLOUD_STORE_VERSION }} + + # Step 6: Build Docker image + - name: Build Docker Image + run: | + IMAGE_NAME="taxonomy-api" + IMAGE_TAG=$(echo "${{ github.ref_name }}_$(echo $GITHUB_SHA | cut -c1-7)" | tr '[:upper:]' '[:lower:]') + docker build -f build/taxonomy-service/Dockerfile -t $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG} . + + echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV + echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV + + # Step 7: Push Docker Image + - name: Push Docker Image + run: | + docker push $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG} + echo "Pushed Docker image: $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG}" \ No newline at end of file diff --git a/README.md b/README.md index 1e4e3d577..6656b3f42 100644 --- a/README.md +++ b/README.md @@ -204,3 +204,45 @@ mvn play2:run ```shell curl http://localhost:9000/health ``` + +### GitHub Actions Workflow Prerequisites + +To ensure the GitHub Actions workflows in this repository function correctly, the following prerequisites must be met: + +1. **Secrets Configuration**: + - Ensure the secrets are configured in your GitHub repository, depending on the value of `REGISTRY_PROVIDER`. The workflow will push the image to the respective container registry if the required credentials are provided. + + - Note: If No REGISTRY_PROVIDER is provided the image will be pushed to GHCR. + + #### GCP (Google Cloud Platform) + - `REGISTRY_PROVIDER`: Set to `gcp` + - `GCP_SERVICE_ACCOUNT_KEY`: Base64-encoded service account key for GCP. + - `REGISTRY_NAME`: GCP registry name (e.g., `asia-south1-docker.pkg.dev`). + - `REGISTRY_URL`: URL of the GCP container registry (e.g., `asia-south1-docker.pkg.dev//`). + + #### DockerHub + - `REGISTRY_PROVIDER`: Set to `dockerhub` + - `REGISTRY_USERNAME`: DockerHub username. + - `REGISTRY_PASSWORD`: DockerHub password. + - `REGISTRY_NAME`: DockerHub registry name (e.g., `docker.io`). + - `REGISTRY_URL`: URL of the DockerHub registry (e.g., `docker.io/`). + + #### Azure Container Registry (ACR) + - `REGISTRY_PROVIDER`: Set to `azure` + - `REGISTRY_USERNAME`: ACR username (service principal or admin username). + - `REGISTRY_PASSWORD`: ACR password (service principal secret or admin password). + - `REGISTRY_NAME`: ACR registry name (e.g., `myregistry.azurecr.io`). + - `REGISTRY_URL`: URL of the ACR registry (e.g., `myregistry.azurecr.io`). + + #### GitHub Container Registry (GHCR) + - `REGISTRY_PROVIDER`: Set to any value other than above (default is GHCR) + - No additional secrets are required. The workflow uses the built-in `GITHUB_TOKEN` provided by GitHub Actions for authentication. + +2. **Environment Variables**: + - The following environment variables must be set in the repository or workflow: + - `CLOUD_STORE_GROUP_ID`: The group ID for cloud storage dependencies. + - `CLOUD_STORE_ARTIFACT_ID`: The artifact ID for cloud storage dependencies. + - `CLOUD_STORE_VERSION`: The version of the cloud storage dependencies. + +Ensure these secrets and variables are added to the repository settings under **Settings > Secrets and variables > Actions**. +By ensuring these prerequisites are met, the workflows in this repository will execute successfully. \ No newline at end of file