Skip to content

Fixing ci build, now using docker hub #3

Fixing ci build, now using docker hub

Fixing ci build, now using docker hub #3

Workflow file for this run

name: Build and Deploy to Docker Hub
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build, tag, and push image to Docker Hub
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_REPOSITORY: ${{ secrets.DOCKER_HUB_REPOSITORY }}
run: |
IMAGE_TAG=latest
REPOSITORY_URI=${DOCKER_HUB_USERNAME}/${DOCKER_HUB_REPOSITORY}
# Build the Docker image
docker build -t $REPOSITORY_URI:$IMAGE_TAG .
# Push the image to Docker Hub
docker push $REPOSITORY_URI:$IMAGE_TAG
- name: Deploy to ECS
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
DOCKER_IMAGE_URI: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
run: |
# Update the ECS service with the new image
aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment