added .env to image tag #7
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 | ||
env: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
REPOSITORY_NAME: openchanjo_gateway | ||
IMAGE_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_PASSWORD }}:latest | ||
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' ./server/src/main/resources/roles-config.json) | ||
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV | ||
# Step 5: Build and tag the Docker image | ||
- name: Build and tag Docker image | ||
run: | | ||
# IMAGE_TAG="${ env.DOCKERHUB_USERNAME }/${ env.REPOSITORY_NAME }:latest" | ||
echo '${{ env.DOCKERHUB_PASSWORD }}' | docker login -u ${{ env.DOCKERHUB_USERNAME }} --password-stdin | ||
docker buildx create --use --name workflowBuilder | ||
docker buildx build --platform=linux/amd64,linux/arm64 -t ${{ env.IMAGE_TAG }} --push . | ||
docker logout |