Change yml file to development #1
This file contains 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 Push Docker Image | |
# Trigger the workflow on push to main branch or pull requests | |
on: | |
push: | |
branches: | |
- development | |
pull_request: | |
branches: | |
- development | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Set up Docker Buildx (required for multi-stage builds) | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# Step 3: Set up Node.js and jq (for JSON parsing) | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: Install jq (JSON parser) | |
run: sudo apt-get update && sudo apt-get install -y jq | |
# Step 4: Extract platform information from roles-config.json | |
- name: Extract platform from roles-config.json | |
id: extract_platform | |
run: | | |
PLATFORM=$(jq -r '.baseUrl.platform' ./roles-config.json) | |
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV | |
# Step 5: Log in to Docker Hub using credentials from GitHub secrets | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# Step 6: Build and tag the Docker image | |
- name: Build and tag Docker image | |
run: | | |
DOCKERHUB_USERNAME="${{ secrets.DOCKERHUB_USERNAME }}" | |
REPOSITORY_NAME="openchanjo_gateway" | |
IMAGE_TAG="${DOCKERHUB_USERNAME}/${REPOSITORY_NAME}:${{ env.PLATFORM }}" | |
docker buildx build --platform linux/amd64 -t $IMAGE_TAG . | |
# Step 7: Push the image to Docker Hub | |
- name: Push Docker image | |
run: | | |
DOCKERHUB_USERNAME="${{ secrets.DOCKERHUB_USERNAME }}" | |
REPOSITORY_NAME="openchanjo_gateway" | |
IMAGE_TAG="${DOCKERHUB_USERNAME}/${REPOSITORY_NAME}:${{ env.PLATFORM }}" | |
docker push $IMAGE_TAG |