Skip to content

updated ci.yml

updated ci.yml #68

Workflow file for this run

name: CI Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
# Build, Test, and Lint Stage
build-and-test:
name: Build, Test, and Lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker Hub Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_API_KEY }}
- name: Build, Test, and Lint with Dev Image
run: |
docker buildx build \
--target dev \
--platform linux/amd64 \
--file development/Dockerfile.prod \
--tag ${{ secrets.DOCKER_USERNAME }}/myapp:dev \
--push \
.
# Production Build Stage
build-prod:
name: Build Production Docker Image
runs-on: ubuntu-latest
needs: build-and-test # Wait for build-and-test job to complete
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker Hub Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_API_KEY }}
- name: Build and Push Production Image
run: |
docker buildx build \
--target prod \
--platform linux/amd64 \
--file development/Dockerfile.prod \
--tag ${{ secrets.DOCKER_USERNAME }}/myapp:latest \
--push \
.
# Release Stage
release:
name: Deploy to Heroku
runs-on: ubuntu-latest
needs: build-prod # Wait for build-prod job to complete
steps:
- name: Docker Hub Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_API_KEY }}
- name: Pull Production Docker image
run: |
docker pull ${{ secrets.DOCKER_USERNAME }}/myapp:latest
- name: Deploy to Heroku
run: |
heroku container:push web --app ${{ secrets.HEROKU_APP_NAME }}
heroku container:release web --app ${{ secrets.HEROKU_APP_NAME }}