Skip to content
Merged
44 changes: 44 additions & 0 deletions .github/actions/registry-login/action.yml
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions .github/workflows/content-service.yml
Original file line number Diff line number Diff line change
@@ -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}"
68 changes: 68 additions & 0 deletions .github/workflows/search-service.yml
Original file line number Diff line number Diff line change
@@ -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}"
68 changes: 68 additions & 0 deletions .github/workflows/taxonomy-service.yml
Original file line number Diff line number Diff line change
@@ -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}"
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,45 @@ mvn play2:run
```shell
curl http://localhost:9000/health
```

### GitHub Actions Workflow Prerequisites
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider clarifying what happens if 'REGISTRY_PROVIDER' is not explicitly set, so users have clear guidance on default behavior.

Copilot uses AI. Check for mistakes.

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/<project_id>/<repository_name>`).

#### 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/<username>`).

#### 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.