Skip to content

Commit

Permalink
Refactor publish-docker-container action.yml to update publish steps …
Browse files Browse the repository at this point in the history
…and use bash shell
  • Loading branch information
f3an committed Oct 13, 2024
1 parent 83b9d34 commit b7869a5
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions publish-docker-container/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,48 @@ env:
runs:
using: "composite"
steps:
# Step 1: Publish to Docker Hub
- name: Publish to Docker Hub
uses: ./publish-container-docker-hub
# Step 1: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Step 2: Log in to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
docker_image_name: ${{ inputs.docker_image_name }}
env:
DOCKERHUB_USERNAME: ${{ env.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ env.DOCKERHUB_TOKEN }}
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}

# Step 3: Build and push the Docker image to Docker Hub
- name: Build and push Docker image to Docker Hub
shell: bash
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--push \
--tag ${{ env.DOCKERHUB_USERNAME }}/${{ inputs.docker_image_name }}:${{ github.sha }} \
--tag ${{ env.DOCKERHUB_USERNAME }}/${{ inputs.docker_image_name }}:latest \
.
# Step 2: Publish to GitHub Container Registry
- name: Publish to GitHub Container Registry
uses: ./publish-container-github
# Step 4: Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
docker_image_name: ${{ inputs.docker_image_name }}
env:
GHCR_TOKEN: ${{ env.GHCR_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ env.GHCR_TOKEN }}

# Step 5: Build and push the Docker image to GitHub Container Registry
- name: Build and push Docker image to GHCR
shell: bash
run: |
# Convert variables to lowercase
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME=$(echo "${{ inputs.docker_image_name }}" | tr '[:upper:]' '[:lower:]')
# Build and push Docker image
docker buildx build \
--platform linux/amd64,linux/arm64 \
--push \
--tag ghcr.io/$REPO_OWNER/$IMAGE_NAME:${{ github.sha }} \
--tag ghcr.io/$REPO_OWNER/$IMAGE_NAME:latest \
.

0 comments on commit b7869a5

Please sign in to comment.