Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action createing docker images #171

Open
visze opened this issue Jan 23, 2025 · 0 comments
Open

Github action createing docker images #171

visze opened this issue Jan 23, 2025 · 0 comments

Comments

@visze
Copy link
Collaborator

visze commented Jan 23, 2025

Here is a possible solution

  1. Create a workflow file in your repository (e.g., .github/workflows/docker-image.yml).

  2. Define the workflow:

 name: Build and Push Docker Image on Release

 on:
   release:
     types: [published]

 jobs:
   build:
     runs-on: ubuntu-latest

     steps:
     - name: Checkout code
       uses: actions/checkout@v3

     - name: Set up Docker Buildx
       uses: docker/setup-buildx-action@v3

     - name: Login to Docker Hub
       uses: docker/login-action@v3
       with:
         username: ${{ secrets.DOCKERHUB_USERNAME }}
         password: ${{ secrets.DOCKERHUB_TOKEN }}

     - name: Build and push Docker image
       uses: docker/build-push-action@v6
       with:
         context: .
         push: true
         tags: user/app:${{ github.sha }}

Explanation:

  • Trigger: The workflow triggers on a release event, specifically when a release is published.
  • Jobs: The build job runs on the latest Ubuntu runner.
  • Steps:
    • Checkout code: Uses the actions/checkout action to check out the repository.
    • Set up Docker Buildx: Uses the docker/setup-buildx-action to set up Docker Buildx.
    • Login to Docker Hub: Uses the docker/login-action to log in to Docker Hub using secrets for the username and password.
    • Build and push Docker image: Uses the docker/build-push-action to build and push the Docker image to Docker Hub. The image is tagged with the commit SHA for uniqueness.

Secrets:

  • DOCKERHUB_USERNAME: Your Docker Hub username.
  • DOCKERHUB_TOKEN: Your Docker Hub access token.

You can store these secrets in your GitHub repository settings under Settings > Secrets and variables > Actions.

This setup ensures that your Docker image is built and pushed to Docker Hub only when a new release is published,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant