Skip to content

🚀 creating a new image in docker #2

🚀 creating a new image in docker

🚀 creating a new image in docker #2

name: Build and Push Docker Image to Docker Hub
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
REGISTRY: docker.io
IMAGE_NAME: dhruvdavee/mini-dev-backend
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up environment variables for Docker Compose
run: |
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "OPENAI_MODEL_NAME=${{ secrets.OPENAI_MODEL_NAME }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "PINECONE_API_KEY=${{ secrets.PINECONE_API_KEY }}" >> .env
echo "PINECONE_ENVIRONMENT=${{ secrets.PINECONE_ENVIRONMENT }}" >> .env
- name: Build the Docker Image for Mini Dev Backend
run: docker-compose build --no-cache --force-rm
test-image:
runs-on: ubuntu-latest
needs: build-image
steps:
- uses: actions/checkout@v2
- name: Test the Docker Image build in previous job
run: docker-compose up -d
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: [build-image, test-image]
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and Push Docker image to Docker Hub
uses: docker/build-push-action@v2
with:
context: "{{defaultContext}}"
push: true
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.output.labels}}