Skip to content

Commit

Permalink
Use GitHub actions to build and push to Docker Hub
Browse files Browse the repository at this point in the history
  • Loading branch information
SteppingHat committed Oct 3, 2024
1 parent 380f9a3 commit 7a2dd4d
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build and Push Docker Image to Docker Hub

on:
push:
branches: [ "dev", "master" ]
pull_request:
branches: [ "dev", "master" ]
types: [ "closed" ]
tags:
workflow_dispatch:

env:
REGISTRY: docker.io
IMAGE_NAME: steppinghat/cgate-server

jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} --no-cache --force-rm .

test:
runs-on: ubuntu-latest
needs: [build]

steps:
- uses: actions/checkout@v2
- name: Test the Docker image
run: docker run -d ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: [build, test]

steps:
- name: Check out the repo
uses: actions/checkout@v3

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

- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: "{{defaultContext}}"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

0 comments on commit 7a2dd4d

Please sign in to comment.