The user is asking about creating a CI/CD pipeline using GitHub Actions and Docker for an Angular application. It seems they want a step-by-step guide, which likely includes a Dockerfile, GitHub Actions workflow YAML, and potentially a deployment recipe.
I need to decide on a deployment target, possibly building and pushing a Docker image to Docker Hub or GitHub Container Registry. I should consider integration tests, caching node modules, and a multi-stage Docker build for compiling the Angular app and serving it via Nginx.Structuring CI/CD Pipeline Guide
I'm going to structure the answer in clear steps: starting with prerequisites, followed by the Dockerfile for a multi-stage build, and then a .dockerignore file.
Next, I'll create a GitHub Actions workflow in .github/workflows/ci-cd.yml that includes jobs for building and testing the app, then building and pushing the Docker image to the GitHub Container Registry. I might also add a deployment job, possibly using SSH. While the user hasn’t specified a deployment target, I can outline two generic options: pushing the image or deploying to a simple server.Completing the Dockerfile and CI/CD Workflow
I’m finalizing the Dockerfile with stages for both building and serving the app with Nginx. It includes installing dependencies, building for production, and copying the output to the Nginx container. I need to remind the user to replace <your-project-name> in the Dockerfile with their specific project name and provide an example of the nginx.conf file.
Next, I’ll structure the .github/workflows/ci-cd.yml to set up Node for testing, cache Node modules, and use the appropriate Docker login and build-push actions. This will help streamline the CI/CD process!Creating the CI/CD Workflow YAML
I’m putting together the CI/CD workflow YAML example. It outlines triggers for pushes and pull requests to the main branch. The environment variables set the GitHub Container Registry and the image name based on the repository.
The jobs section includes build-test, performing checks and tests on the app using Node, and a docker job to log in and push the Docker image to the registry. I should also mention adding an optional deploy job, which could pull the latest image and restart the container on a production server.Creating the Deployment Job
I’m setting up a deployment job using appleboy/ssh-action to run remote commands securely, utilizing secrets for SSH connection details. The job is conditioned to run only on the main branch after the Docker job completes.
I'll include commands to log in to the GitHub Container Registry, pull the latest Docker image, and manage the Angular app container. I need to mention how to use a DEPLOY_GITHUB_TOKEN or potentially a personal access token for authentication.
I'll also emphasize the importance of using ChromeHeadless for tests if necessary, keeping everything concise while including necessary configurations and explanations about secrets. Below is a complete example of a CI/CD setup for an Angular app that:
Runs lint, unit tests, and production build on every push/PR
Builds a Docker image that serves the Angular app via Nginx
Pushes the image to GitHub Container Registry (GHCR)
(Optional) Deploys to a remote server via SSH using Docker
You can adapt pieces as needed.
1. Prerequisites
Angular app created (e.g. with Angular CLI) and committed to GitHub.