Docker action
This commit is contained in:
parent
c257622ad7
commit
28973a5059
68
.github/workflows/docker-image.yml
vendored
Normal file
68
.github/workflows/docker-image.yml
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DH_REGISTRY: docker.io
|
||||
GH_REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
REPOSITORY: ${{ github.event.repository.name }}
|
||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Provide default tag username
|
||||
if: ${{ env.DOCKER_USERNAME == '' }}
|
||||
run: |
|
||||
echo "DOCKER_USERNAME=remote" >> $GITHUB_ENV
|
||||
|
||||
- name: Build the Docker image
|
||||
run: docker build . --file Dockerfile --tag "$DOCKER_USERNAME/$REPOSITORY:latest"
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
|
||||
with:
|
||||
registry: ${{ env.DH_REGISTRY }}
|
||||
username: ${{ env.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Push to Docker Hub
|
||||
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
|
||||
run: docker push "$DOCKER_USERNAME/$REPOSITORY:latest"
|
||||
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ${{ env.GH_REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: ${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
|
||||
- name: Push to GitHub
|
||||
uses: docker/build-push-action@v2
|
||||
if: github.event_name == 'push'
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user