Docker Hub workflow
Path to file (view file on GitHub)
The original file is located at the following path:
.github / workflows / deployment_on_dockerhub.yml
To register secrets in GitHub:
- Navigate to your repository on GitHub.
- Click on
Settings
.- In the left sidebar, click on
Secrets and variables
and thenActions
.- Click the
New repository secret
button.- Add a name for your secret (e.g.,
DOCKER_USER
) and its value.- Click
Add secret
to save.Repeat these steps for
DOCKER_PASSWORD
secret.
This GitHub Actions workflow is designed to automate the process of building and publishing Docker images to Docker Hub whenever a new release is published. The essential elements of this workflow are as follows:
Workflow Name
- name: Publish image in Docker Hub
Triggers
- on:
- release: Triggers when a release is published.
Jobs
- push_to_registry: This job runs on the latest Ubuntu environment (
ubuntu-latest
).
Steps
- Check out the Repository
- Uses the
actions/checkout@v3
action to checkout the repository.
- Uses the
- Log in to Docker Hub
- Uses the
docker/login-action
pinned to a specific commit (f4ef78c080cd8ba55a85445d5b36e214a81df20a
) to log in to Docker Hub with credentials stored in GitHub Secrets:username: $ password: $
- Uses the
- Build and Push Docker Image
- Builds the Docker image using the
Dockerfile.prod
file and tags it with the release tag name:docker build -t drorganvidez/uvlhub:$ -f Dockerfile.prod .
- Pushes the tagged Docker image to Docker Hub:
docker push drorganvidez/uvlhub:$
- Builds the Docker image using the
- Tag and Push Latest
- Tags the built Docker image with
latest
and pushes it to Docker Hub:docker tag drorganvidez/uvlhub:$ drorganvidez/uvlhub:latest docker push drorganvidez/uvlhub:latest
- Tags the built Docker image with
Notes
- Third-Party Actions: This workflow uses third-party actions that are not certified by GitHub. They are governed by separate terms of service, privacy policy, and support documentation.
- Pinning Actions: GitHub recommends pinning actions to a commit SHA to ensure stability and predictability. The workflow uses a pinned commit SHA for the Docker login action.