Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sagarmaheshwary/github-actions-demo

Demo NodeJS and Docker CI/CD Pipeline using Github Actions.
https://github.com/sagarmaheshwary/github-actions-demo

cicd docker github-actions nodejs

Last synced: 10 days ago
JSON representation

Demo NodeJS and Docker CI/CD Pipeline using Github Actions.

Awesome Lists containing this project

README

        

# NODEJS - GITHUB ACTIONS DEMO

This repository is set up with GitHub Actions to automate the process of building and deploying the Docker image. The CI/CD pipeline includes the following key steps:

### Building and Pushing Docker Image

- The workflow is triggered on pushes to the master branch and when pull requests to master are merged.
- It checks out the code, sets up Docker Buildx, and logs into Docker Hub using the provided credentials.
- It builds the Docker image and pushes it to Docker Hub with tags for both latest and the current commit SHA.

### Running Tests

- Before building the Docker image, the pipeline runs npm run test to execute the tests for the application.
- If any tests fail, the pipeline will fail, preventing the Docker image from being built or pushed.

### Simulating Test Success and Failure

- You can simulate a passing test by modifying the test script in your package.json like this:

```json
"scripts": {
"test": "echo \"Test successful!\""
}
```

- To simulate a failing test, you can change the script to:

```json
"scripts": {
"test": "echo \"Test failed!\" && exit 1"
}
```

- In either case, the results of npm run test will determine whether the pipeline continues to build and push the Docker image.

### Variables and Secrets

- In your GitHub repository settings, navigate to **Secrets and variables > actions > Repository Secrets** and add the following secrets:
- DOCKER_USERNAME: Your Docker Hub username.
- DOCKER_PASSWORD: Your Docker Hub password.
- Define a variable for your Docker Hub repository by navigating to **Settings > Secrets and variables > Actions > Repository Variables**.
- DOCKER_HUB_REPO: Set this variable to the name of your Docker Hub repository (e.g., your-dockerhub-username/node-app).