Build and Push Docker Image #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Docker Image | |
on: | |
push: | |
branches: | |
- main | |
release: | |
types: [created] | |
workflow_dispatch: | |
permissions: | |
packages: write | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Log in to GitHub Container Registry | |
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Build and tag Docker image | |
run: | | |
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
TAG_NAME=${{ github.event.release.tag_name || 'latest' }} | |
docker build -t ghcr.io/$REPO_OWNER/squadds_env:$TAG_NAME . | |
docker tag ghcr.io/$REPO_OWNER/squadds_env:$TAG_NAME ghcr.io/$REPO_OWNER/squadds_env:latest | |
- name: Push Docker image to GitHub Packages | |
run: | | |
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
TAG_NAME=${{ github.event.release.tag_name || 'latest' }} | |
docker push ghcr.io/$REPO_OWNER/squadds_env:$TAG_NAME | |
docker push ghcr.io/$REPO_OWNER/squadds_env:latest |