小写 #57
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: Docker | |
on: | |
push: | |
branches: '*' | |
tags: '*' | |
pull_request: | |
branches: "main" | |
env: | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
LOWERCASE_IMAGE_NAME: "" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Update Submodule | |
run: git submodule update --init --recursive | |
- name: Composer Install | |
uses: php-actions/composer@v6 | |
with: | |
php_version: "8.1" | |
working_dir: "lsky-pro" | |
- name: Install cosign | |
uses: sigstore/[email protected] | |
with: | |
cosign-release: 'v2.2.4' | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Convert IMAGE_NAME to lowercase | |
run: | | |
IMAGE_NAME=${{ env.IMAGE_NAME }} | |
echo "LOWERCASE_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log in to Docker Hub | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ghcr.io/${{ env.LOWERCASE_IMAGE_NAME }}:main | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Sign the published Docker image | |
env: | |
TAGS: ghcr.io/${{ env.LOWERCASE_IMAGE_NAME }}:main | |
DIGEST: ${{ steps.build-and-push.outputs.digest }} | |
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} | |
# 发布tag时推送到dockerhub | |
- name: Push Docker image to Docker Hub (on tag push) | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.LOWERCASE_IMAGE_NAME }}:latest | |
${{ env.LOWERCASE_IMAGE_NAME }}:${{ github.ref_name }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Sign the published Docker image | |
if: startsWith(github.ref, 'refs/tags/') | |
env: | |
TAGS: | | |
${{ env.LOWERCASE_IMAGE_NAME }}:latest | |
${{ env.LOWERCASE_IMAGE_NAME }}:${{ github.ref_name }} | |
DIGEST: ${{ steps.build-and-push.outputs.digest }} | |
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} | |