Skip to content

Update docker-image.yml #15

Update docker-image.yml

Update docker-image.yml #15

Workflow file for this run

name: Sync CI/CD Workflow
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout code
uses: actions/checkout@v4
# Step 2: Set up Node.js
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20 # Specify the Node.js version
cache: 'npm'
# Step 3: Install dependencies
- name: Install dependencies
run: npm install
# Step 4: Build the Next.js project
- name: Build the Next.js application
run: npm run build
env:
UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
PUSHER_APP_ID: ${{ secrets.PUSHER_APP_ID }}
NEXT_PUBLIC_PUSHER_KEY: ${{ secrets.NEXT_PUBLIC_PUSHER_KEY }}
PUSHER_SECRET: ${{ secrets.PUSHER_SECRET }}
PUSHER_CLUSTER: ${{ secrets.PUSHER_CLUSTER }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
# Step 5: Upload build artifacts (optional)
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: nextjs-build
path: .next
include-hidden-files: true
if-no-files-found: warn
# Step 6: Build and Push Docker Image
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Docker Image
run: |
IMAGE_NAME=${{ secrets.DOCKER_IMAGE_NAME }}:latest
docker build \
--build-arg UPSTASH_REDIS_REST_URL=${{ secrets.UPSTASH_REDIS_REST_URL }} \
--build-arg UPSTASH_REDIS_REST_TOKEN=${{ secrets.UPSTASH_REDIS_REST_TOKEN }} \
--build-arg GOOGLE_CLIENT_ID= ${{ secrets.GOOGLE_CLIENT_ID }} \
--build-arg GOOGLE_CLIENT_SECRET= ${{ secrets.GOOGLE_CLIENT_SECRET }} \
--build-arg NEXTAUTH_SECRET= ${{ secrets.NEXTAUTH_SECRET }} \
--build-arg PUSHER_APP_ID= ${{ secrets.PUSHER_APP_ID }} \
--build-arg NEXT_PUBLIC_PUSHER_KEY= ${{ secrets.NEXT_PUBLIC_PUSHER_KEY }} \
--build-arg PUSHER_SECRET= ${{ secrets.PUSHER_SECRET }} \
--build-arg PUSHER_CLUSTER= ${{ secrets.PUSHER_CLUSTER }} \
--build-arg NEXTAUTH_URL= ${{ secrets.NEXTAUTH_URL }} \
-t $IMAGE_NAME .
docker push $IMAGE_NAME
deploy:
runs-on: ubuntu-latest
needs: build
steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v4
# Step 2: Setup Node.js
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20 # Specify the Node.js version
cache: 'npm'
# Step 3: Download build artifacts
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: nextjs-build
# Step 4: Deploy to Vercel
- name: Deploy to Vercel
run: npx vercel --prod
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
PUSHER_APP_ID: ${{ secrets.PUSHER_APP_ID }}
NEXT_PUBLIC_PUSHER_KEY: ${{ secrets.NEXT_PUBLIC_PUSHER_KEY }}
PUSHER_SECRET: ${{ secrets.PUSHER_SECRET }}
PUSHER_CLUSTER: ${{ secrets.PUSHER_CLUSTER }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}