Skip to content

Build and Push Docker Image #2

Build and Push Docker Image

Build and Push Docker Image #2

name: Build and Push Docker Image
on:
workflow_run:
workflows: [Build and Test Docker Image]
types: [completed]
branches:
- main
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: get-name
run: |
echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV
echo "REPO_OWNER=$(echo ${{ github.repository_owner}} | tr '[:upper:]' '[:lower:]' )" >> $GITHUB_ENV
- name: print-name
run: |
echo "${{ env.REPO_NAME }}"
echo "${{ env.REPO_OWNER }}"
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: |
docker build \
-t ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ github.sha }} \
-t ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest . -f docker/Dockerfile
- name: Push Docker image
run: |
docker push ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ github.sha }} &&
docker push ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest