DEV Community

Tahsin Abrar
Tahsin Abrar

Posted on

Dockerizing a Project Locally and Deploying Docker Images to Azure Using GitHub Actions (CI/CD)

Guide to Dockerizing and Deploying:

Image description

1. Build the Project

Start by building the project locally. Use the command:

npm run build
Enter fullscreen mode Exit fullscreen mode

2. Update the Dockerfile

Open the Dockerfile and temporarily comment out the lines where environment variables (export commands) are defined. This is just for the local setup.

3. Update the docker-compose.yml

Next, go to your docker-compose.yml file and do the same — comment out any lines referencing environment variables.

4. Create an .env.production File

Now, create a new file called .env.production in the project root. Add the following variables with the appropriate values:

NEXT_PUBLIC_PUSHER_KEY=your_pusher_key
PUSHER_SECRET=your_pusher_secret
NEXT_PUBLIC_PUSHER_CLUSTER=your_pusher_cluster
PUSHER_APP_ID=your_pusher_app_id
SUPABASE_URL_LC_CHATBOT=your_supabase_url
SUPABASE_API_KEY=your_supabase_api_key
Enter fullscreen mode Exit fullscreen mode

5. Build the Docker Image

Run the following command to build the Docker image:

docker-compose build
Enter fullscreen mode Exit fullscreen mode

6. Troubleshooting Errors

If the build process fails, check the logs and fix any issues before proceeding.

7. Configure GitHub Secrets

To enable deployment with GitHub Actions, set up the required environment variables in your repository settings:

  1. Go to SettingsSecrets and VariablesActions.
  2. Add these secrets:
   AZUREAPPSERVICE_PUBLISHPROFILE=your_azure_publish_profile
   NEXT_PUBLIC_PUSHER_KEY=your_pusher_key
   PUSHER_SECRET=your_pusher_secret
   NEXT_PUBLIC_PUSHER_CLUSTER=your_pusher_cluster
   PUSHER_APP_ID=your_pusher_app_id
   SUPABASE_URL_LC_CHATBOT=your_supabase_url
   SUPABASE_API_KEY=your_supabase_api_key
   AZURE_CONTAINER_PASSWORD=your_container_password
   AZURE_CONTAINER_USERNAME=your_container_username
Enter fullscreen mode Exit fullscreen mode

8. Undo Temporary Changes

Before committing your changes:

  • Undo the comments in the Dockerfile and docker-compose.yml so that the build-time variables are used as intended.

9. Finalize and Push the Code

Once everything is ready:

  1. Commit the changes:
   git commit -m "Set up Docker and GitHub Actions for Azure deployment"
Enter fullscreen mode Exit fullscreen mode
  1. Push the code to the main branch:
   git push origin main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)