Build and Package Content Service #8
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: Build and Package Content Service | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - '*' | |
| jobs: | |
| build-and-package: | |
| 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: Check for build cache | |
| - name: Restore Maven Build Cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| # 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: Set up Login to Docker registry | |
| - name: Determine registry and login | |
| run: | | |
| if [[ -n "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}" ]]; then | |
| echo "Using Google Container Registry" | |
| echo "${{ secrets.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 ${{ secrets.REGISTRY_NAME }} | |
| REGISTRY_URL=$(echo "${{ secrets.REGISTRY_URL }}" | tr '[:upper:]' '[:lower:]') | |
| elif [[ -n "${{ secrets.REGISTRY_USERNAME }}" && -n "${{ secrets.REGISTRY_PASSWORD }}" ]]; then | |
| echo "Logging in to custom Docker registry" | |
| echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_NAME }} \ | |
| --username ${{ secrets.REGISTRY_USERNAME }} --password-stdin | |
| REGISTRY_URL=$(echo "${{ secrets.REGISTRY_URL }}" | tr '[:upper:]' '[:lower:]') | |
| else | |
| echo "Using GitHub Container Registry (GHCR)" | |
| REPO_NAME_LOWERCASE=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]') | |
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| REGISTRY_URL="ghcr.io/$REPO_NAME_LOWERCASE" | |
| fi | |
| echo "REGISTRY_URL=${REGISTRY_URL}" >> $GITHUB_ENV | |
| # 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 | |
| - name: Push Docker Image | |
| run: | | |
| docker push $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG} |