Skip to content

Commit

Permalink
Merge pull request #3 from rene-bos/build-docker-images
Browse files Browse the repository at this point in the history
Build docker images
  • Loading branch information
rene-bos authored Jan 12, 2022
2 parents 3f5c9c5 + ec84c7e commit 41d2af6
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 5 deletions.
138 changes: 138 additions & 0 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Build Docker images

on:
push:
branches:
- main
- release-*
tags:
- v*

env:
REGISTRY: ghcr.io

jobs:
ci:
name: CI
uses: rene-bos/iw-ghdw-app/.github/workflows/ci.yml@main

build-source:
name: Build source
needs: ci
runs-on: ubuntu-latest
container:
image: ghcr.io/rene-bos/iw-ghdw-php:8.1-ci-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install PHP dependencies
run: composer install --no-dev --no-interaction --optimize-autoloader

- name: Zip build artifact
run: zip -r build-source.zip .

- name: Upload build artifact
uses: actions/upload-artifact@v2
with:
name: build-source
path: build-source.zip
retention-days: 7

build-and-push-php:
name: Build & push PHP image
needs: build-source
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
IMAGE_NAME: rene-bos/iw-ghdw-app-php
IMAGE_TITLE: IW GHDW App | PHP
steps:
- name: Download build source
uses: actions/download-artifact@v2
with:
name: build-source

- name: Unzip build source artifact
run: |
unzip build-source.zip -d .
rm build-source.zip
- name: Log in to container registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Extract metadata (tags, labels) for Docker
id: meta-php
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=edge,branch=main
labels: |
- org.opencontainers.image.title=${{ env.IMAGE_TITLE }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
file: ./infrastructure/docker/php/Dockerfile
context: .
push: true
tags: ${{ steps.meta-php.outputs.tags }}
labels: ${{ steps.meta-php.outputs.labels }}

build-and-push-web:
name: Build & push web image
needs: build-source
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
IMAGE_NAME: rene-bos/iw-ghdw-app-web
IMAGE_TITLE: IW GHDW App | Web
steps:
- name: Download build source
uses: actions/download-artifact@v2
with:
name: build-source

- name: Unzip build source artifact
run: |
unzip build-source.zip -d .
rm build-source.zip
- name: Log in to container registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Extract metadata (tags, labels) for Docker
id: meta-web
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=edge,branch=main
labels: |
- org.opencontainers.image.title=${{ env.IMAGE_TITLE }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
file: ./infrastructure/docker/web/Dockerfile
context: .
push: true
tags: ${{ steps.meta-web.outputs.tags }}
labels: ${{ steps.meta-web.outputs.labels }}
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: CI
on:
push:
branches:
- main
- release-*
pull_request: ~
pull_request:
workflow_call:

jobs:
code-style:
Expand Down
14 changes: 14 additions & 0 deletions infrastructure/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.7"

services:
php:
build:
context: ./../..
dockerfile: ./infrastructure/docker/php/Dockerfile

web:
build:
context: ./../..
dockerfile: ./infrastructure/docker/web/Dockerfile
ports:
- "6002:80"
6 changes: 6 additions & 0 deletions infrastructure/docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ghcr.io/rene-bos/iw-ghdw-php:8.1-latest

COPY . /app

# Ensure PHP can write in the `var` folder
RUN chmod -R 0777 /app/var
3 changes: 3 additions & 0 deletions infrastructure/docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM ghcr.io/rene-bos/iw-ghdw-nginx:symfony-latest

COPY . /app

0 comments on commit 41d2af6

Please sign in to comment.