mirror of
https://github.com/seepine/action-docker-build-push.git
synced 2025-01-18 14:56:36 +08:00
feat: support auto generate tags
This commit is contained in:
parent
e61198e414
commit
04f0a2ab06
43
README.md
43
README.md
@ -4,17 +4,40 @@
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
Just set registry info, it will build and push.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: Docker build push
|
||||||
|
uses: seepine/action-docker-build-push@v1
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
```
|
||||||
|
|
||||||
|
The tags auto generate from `refs`.Eg the repo is `github.com/seepine/demo`, with registry is `ghcr.io` and with username is `seepine`.
|
||||||
|
|
||||||
|
- trigger push branch eg `main`
|
||||||
|
- `ghcr.io/seepine/demo:main`
|
||||||
|
- `ghcr.io/seepine/demo:latest`
|
||||||
|
- trigger push tag eg `v1.2.3`
|
||||||
|
- `ghcr.io/seepine/demo:1.2.3`
|
||||||
|
- `ghcr.io/seepine/demo:latest`
|
||||||
|
|
||||||
|
## Custom tags
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Docker build push
|
- name: Docker build push
|
||||||
uses: seepine/action-docker-build-push@v1
|
uses: seepine/action-docker-build-push@v1
|
||||||
with:
|
with:
|
||||||
registry: docker.io
|
registry: docker.io
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: zhangsan
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
tags: |
|
||||||
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:latest
|
docker.io/zhangsan/demo:latest
|
||||||
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:1.2.3
|
docker.io/zhangsan/demo:1.2.3
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set dockerfile
|
## Set dockerfile
|
||||||
@ -23,15 +46,12 @@
|
|||||||
- name: Docker build push
|
- name: Docker build push
|
||||||
uses: seepine/action-docker-build-push@v1
|
uses: seepine/action-docker-build-push@v1
|
||||||
with:
|
with:
|
||||||
registry: docker.io
|
registry: ghcr.io
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
context: . # default .
|
context: . # default .
|
||||||
file: ./build/Dockerfile # default Dockerfile
|
file: ./build/Dockerfile # default Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
|
||||||
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:latest
|
|
||||||
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:1.2.3
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set proxy
|
## Set proxy
|
||||||
@ -57,11 +77,8 @@ jobs:
|
|||||||
- name: Docker build push
|
- name: Docker build push
|
||||||
uses: seepine/action-docker-build-push@v1
|
uses: seepine/action-docker-build-push@v1
|
||||||
with:
|
with:
|
||||||
registry: docker.io
|
registry: ghcr.io
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
|
||||||
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:latest
|
|
||||||
docker.io/${{ secrets.DOCKER_USERNAME }}/demo:1.2.3
|
|
||||||
```
|
```
|
||||||
|
34
action.yml
34
action.yml
@ -24,10 +24,13 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: 'Dockerfile'
|
default: 'Dockerfile'
|
||||||
tags:
|
tags:
|
||||||
description: "List of tags"
|
description: "List/CSV of tags"
|
||||||
required: true
|
required: false
|
||||||
|
labels:
|
||||||
|
description: "List of labels"
|
||||||
|
required: false
|
||||||
platforms:
|
platforms:
|
||||||
description: "List of target platforms for build"
|
description: "List/CSV of target platforms for build"
|
||||||
required: false
|
required: false
|
||||||
push:
|
push:
|
||||||
description: "Push is a shorthand for --output=type=registry"
|
description: "Push is a shorthand for --output=type=registry"
|
||||||
@ -94,6 +97,28 @@ runs:
|
|||||||
- name: echo Build and push
|
- name: echo Build and push
|
||||||
run: echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Build and push"
|
run: echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Build and push"
|
||||||
|
|
||||||
|
- name: Get docker meta
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
if [ -n "${{ inputs.tags }}" ]; then
|
||||||
|
echo TAGS=$(echo "${{ inputs.tags }}" | tr '\n' ',' | sed 's/,$//') >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}')
|
||||||
|
REPO_VERSION=$(echo ${{ github.ref }} | awk -F"/" '{print $3}' | awk -F"v" '{print (NF>1) ? $2 : $1}')
|
||||||
|
if [ -n "${{ inputs.registry }}" ]; then
|
||||||
|
TAGS="${{ inputs.registry }}/${{ inputs.username }}/$REPO_NAME:latest"
|
||||||
|
echo "TAGS=$TAGS,${{ inputs.registry }}/${{ inputs.username }}/$REPO_NAME:$REPO_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
TAGS="${{ inputs.username }}/$REPO_NAME:latest"
|
||||||
|
echo "TAGS=$TAGS,${{ inputs.username }}/$REPO_NAME:$REPO_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: echo Get docker meta
|
||||||
|
run: |
|
||||||
|
echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] ⚙️ Get docker meta"
|
||||||
|
echo TAGS=${{ steps.meta.outputs.TAGS }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
@ -101,7 +126,8 @@ runs:
|
|||||||
file: ${{ inputs.file }}
|
file: ${{ inputs.file }}
|
||||||
platforms: ${{ inputs.platforms }}
|
platforms: ${{ inputs.platforms }}
|
||||||
push: ${{ inputs.push }}
|
push: ${{ inputs.push }}
|
||||||
tags: ${{ inputs.tags }}
|
tags: ${{ steps.meta.outputs.TAGS }}
|
||||||
|
labels: ${{ inputs.labels }}
|
||||||
cache-from: type=local,src=/opt/docker-cache/.build-cache
|
cache-from: type=local,src=/opt/docker-cache/.build-cache
|
||||||
cache-to: type=local,dest=/opt/docker-cache/.build-cache,mode=max
|
cache-to: type=local,dest=/opt/docker-cache/.build-cache,mode=max
|
||||||
build-args: |
|
build-args: |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user