Skip to content

Commit c868a50

Browse files
committed
chore: add Docker support with Dockerfile and workflows for CI/CD
1 parent dabeff9 commit c868a50

File tree

4 files changed

+143
-2
lines changed

4 files changed

+143
-2
lines changed

.dockerignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
bootstrap/cache/services.php
2+
3+
storage/app/*
4+
storage/framework/cache/*
5+
storage/framework/sessions/*
6+
storage/framework/views/*
7+
storage/logs/*
8+
9+
vendor/**/test*
10+
vendor/**/tests*
11+
vendor/**/Tests*
12+
13+
**/*node_modules
14+
15+
**.git
16+
.idea
17+
**.gitignore
18+
**.gitattributes
19+
**.sass-cache
20+
*.env*
21+
22+
*.config.js
23+
?ulpfile.js
24+
?untfile.js
25+
package.json
26+
phpunit.xml
27+
readme.md
28+
phpspec.yml
29+
30+
Dockerfile
31+
docker-compose.yml
32+
run
33+
run.ps1
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: Laravel
33
on:
44
push:
55
branches: ["master"]
6-
pull_request:
7-
branches: ["master"]
86

97
jobs:
108
laravel-tests:
@@ -74,3 +72,9 @@ jobs:
7472
DB_CONNECTION: sqlite
7573
DB_DATABASE: database/database.sqlite
7674
run: php artisan test
75+
76+
# Publish Artifact for later use
77+
- name: Publish Artifact
78+
uses: actions/[email protected]
79+
with:
80+
name: laravel-app

.github/workflows/publish.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
tags: ["v*.*.*"]
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: read
18+
packages: write
19+
id-token: write
20+
21+
steps:
22+
# Download the build artifact
23+
- name: Download a Build Artifact
24+
uses: actions/[email protected]
25+
with:
26+
name: laravel-app
27+
28+
- name: Install cosign
29+
if: github.event_name != 'pull_request'
30+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20
31+
with:
32+
cosign-release: "v2.2.4"
33+
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226
36+
37+
- name: Log into registry ${{ env.REGISTRY }}
38+
if: github.event_name != 'pull_request'
39+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
40+
with:
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Extract Docker metadata
46+
id: meta
47+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
48+
with:
49+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
50+
51+
- name: Build and push Docker image
52+
id: build-and-push
53+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
54+
with:
55+
context: .
56+
push: ${{ github.event_name != 'pull_request' }}
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max
61+
62+
- name: Sign the published Docker image
63+
if: ${{ github.event_name != 'pull_request' }}
64+
env:
65+
TAGS: ${{ steps.meta.outputs.tags }}
66+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
67+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
68+
69+
# Build docker image
70+
- name: Build the Docker image
71+
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM php:8.2
2+
3+
# Update Container
4+
RUN apt-get update -y && apt-get install -y openssl zip unzip git
5+
6+
# Get Composer
7+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
8+
9+
# Install PHP Extensions
10+
RUN apt-get install -y libonig-dev libpq-dev
11+
RUN docker-php-ext-install pdo mbstring pdo_mysql
12+
13+
# Set Working Directory
14+
WORKDIR /app
15+
COPY . /app
16+
17+
# Install Composer Dependencies
18+
RUN composer install --no-dev --prefer-dist --no-interaction --no-progress
19+
20+
# Install NPM
21+
RUN apt-get install -y npm
22+
23+
# Install NPM Dependencies
24+
RUN npm install
25+
26+
# Build NPM
27+
RUN npm run build
28+
29+
# Run Server
30+
CMD php artisan serve --host=0.0.0.0 --port=8000
31+
32+
# Expose Port
33+
EXPOSE 8000

0 commit comments

Comments
 (0)