Skip to content

Commit fd22d30

Browse files
authored
Update docker-publish.yml
1 parent badbe58 commit fd22d30

File tree

1 file changed

+54
-63
lines changed

1 file changed

+54
-63
lines changed
Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,90 @@
1-
name: Docker
2-
3-
# This workflow uses actions that are not certified by GitHub.
4-
# They are provided by a third-party and are governed by
5-
# separate terms of service, privacy policy, and support
6-
# documentation.
1+
name: CI/CD
72

83
on:
9-
schedule:
10-
- cron: '21 2 * * *'
114
push:
12-
branches: [ "main" ]
13-
# Publish semver tags as releases.
14-
tags: [ 'v*.*.*' ]
5+
branches: ["main"]
6+
tags: ["v*.*.*"]
157
pull_request:
16-
branches: [ "main" ]
8+
branches: ["main"]
179

1810
env:
19-
# Use docker.io for Docker Hub if empty
2011
REGISTRY: ghcr.io
21-
# github.repository as <account>/<repo>
2212
IMAGE_NAME: ${{ github.repository }}
2313

24-
2514
jobs:
26-
build:
2715

16+
tests:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: '8.3'
25+
extensions: mbstring, intl, zip, bcmath
26+
coverage: none
27+
28+
- name: Copy .env
29+
run: cp .env.example .env
30+
31+
- name: Prepare Laravel directories
32+
run: |
33+
mkdir -p storage/framework/{sessions,views,cache}
34+
mkdir -p storage/logs
35+
mkdir -p bootstrap/cache
36+
chmod -R 775 storage bootstrap/cache
37+
38+
- name: Install Dependencies
39+
run: composer install --no-interaction --prefer-dist
40+
41+
- name: Generate key
42+
run: php artisan key:generate
43+
44+
- name: Run PHPUnit
45+
env:
46+
APP_ENV: testing
47+
DB_CONNECTION: sqlite
48+
DB_DATABASE: ':memory:'
49+
run: vendor/bin/phpunit
50+
51+
52+
build:
53+
needs: tests
2854
runs-on: ubuntu-latest
2955
permissions:
3056
contents: read
3157
packages: write
32-
# This is used to complete the identity challenge
33-
# with sigstore/fulcio when running outside of PRs.
3458
id-token: write
3559

60+
if: github.event_name != 'pull_request'
61+
3662
steps:
37-
- name: Checkout repository
38-
uses: actions/checkout@v4
39-
40-
# Install the cosign tool except on PR
41-
# https://github.com/sigstore/cosign-installer
42-
- name: Install cosign
43-
if: github.event_name != 'pull_request'
44-
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
45-
with:
46-
cosign-release: 'v2.2.4'
47-
48-
# Set up BuildKit Docker container builder to be able to build
49-
# multi-platform images and export cache
50-
# https://github.com/docker/setup-buildx-action
51-
- name: Set up Docker Buildx
52-
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
53-
54-
# Login against a Docker registry except on PR
55-
# https://github.com/docker/login-action
56-
- name: Log into registry ${{ env.REGISTRY }}
57-
if: github.event_name != 'pull_request'
58-
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
63+
- uses: actions/checkout@v4
64+
65+
- uses: docker/setup-buildx-action@v3
66+
67+
- name: Log into registry
68+
if: startsWith(github.ref, 'refs/tags/')
69+
uses: docker/login-action@v3
5970
with:
6071
registry: ${{ env.REGISTRY }}
6172
username: ${{ github.actor }}
6273
password: ${{ secrets.GITHUB_TOKEN }}
6374

64-
# Extract metadata (tags, labels) for Docker
65-
# https://github.com/docker/metadata-action
6675
- name: Extract Docker metadata
6776
id: meta
68-
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
77+
uses: docker/metadata-action@v5
6978
with:
7079
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
7180

72-
# Build and push Docker image with Buildx (don't push on PR)
73-
# https://github.com/docker/build-push-action
7481
- name: Build and push Docker image
75-
id: build-and-push
76-
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
82+
uses: docker/build-push-action@v5
7783
with:
7884
context: .
7985
file: ./docker/common/php-fpm/Dockerfile
80-
push: ${{ github.event_name != 'pull_request' }}
86+
push: ${{ startsWith(github.ref, 'refs/tags/') }}
8187
tags: ${{ steps.meta.outputs.tags }}
8288
labels: ${{ steps.meta.outputs.labels }}
8389
cache-from: type=gha
8490
cache-to: type=gha,mode=max
85-
86-
# Sign the resulting Docker image digest except on PRs.
87-
# This will only write to the public Rekor transparency log when the Docker
88-
# repository is public to avoid leaking data. If you would like to publish
89-
# transparency data even for private images, pass --force to cosign below.
90-
# https://github.com/sigstore/cosign
91-
- name: Sign the published Docker image
92-
if: ${{ github.event_name != 'pull_request' }}
93-
env:
94-
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
95-
TAGS: ${{ steps.meta.outputs.tags }}
96-
DIGEST: ${{ steps.build-and-push.outputs.digest }}
97-
# This step uses the identity token to provision an ephemeral certificate
98-
# against the sigstore community Fulcio instance.
99-
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)