Skip to content

Commit b0579f5

Browse files
committed
feat: add docker build
1 parent 425f2e1 commit b0579f5

File tree

2 files changed

+93
-20
lines changed

2 files changed

+93
-20
lines changed

.github/workflows/docker.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Create and publish a Docker image
2+
on:
3+
push:
4+
branches: ['release']
5+
pull_request:
6+
paths:
7+
- Dockerfile
8+
- .github/workflows/docker.yml
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
jobs:
13+
build-and-push-image:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Log in to the Container registry
23+
uses: docker/login-action@master
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta-drafter
31+
uses: docker/metadata-action@master
32+
with:
33+
images: ghcr.io/${{ github.repository }}/drafter
34+
35+
- name: Extract metadata (tags, labels) for Docker
36+
id: meta
37+
uses: docker/metadata-action@master
38+
with:
39+
images: ghcr.io/${{ github.repository }}
40+
41+
- name: Build and push Docker image
42+
uses: docker/build-push-action@master
43+
with:
44+
context: .
45+
push: true
46+
tags: ${{ steps.meta-drafter.outputs.tags }}
47+
labels: ${{ steps.meta-drafter.outputs.labels }}
48+
target: drafter-build
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@master
52+
with:
53+
context: .
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
target: phpdraft

Dockerfile

+36-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
1-
FROM apiaryio/drafter:latest as drafter
2-
FROM composer:latest as composer
3-
4-
FROM php:8.1-cli-alpine as build
5-
RUN apk add --no-cache \
6-
$PHPIZE_DEPS \
7-
openssl-dev
8-
RUN pecl install uopz \
9-
&& docker-php-ext-enable uopz
10-
RUN echo "phar.readonly = 0" > "$PHP_INI_DIR/conf.d/phar.ini"
11-
COPY --from=composer /usr/bin/composer /usr/bin/composer
12-
COPY . /usr/src/phpdraft
1+
FROM debian:bullseye-slim AS drafter-build
2+
RUN apt-get update && \
3+
apt-get install --yes curl ca-certificates
4+
5+
RUN curl -L --fail -o drafter.tar.gz https://github.com/apiaryio/drafter/releases/download/v5.1.0/drafter-v5.1.0.tar.gz
6+
RUN install -d /usr/src/drafter
7+
RUN tar -xvf drafter.tar.gz --strip-components=1 --directory /usr/src/drafter
8+
9+
WORKDIR /usr/src/drafter
10+
11+
RUN apt-get install --yes cmake g++
12+
13+
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
14+
RUN cmake --build build
15+
RUN cmake --install build
16+
17+
CMD drafter
18+
19+
FROM composer:latest AS composer
20+
21+
FROM php:8.3-cli-bullseye AS phpdraft-build
22+
1323
WORKDIR /usr/src/phpdraft
14-
RUN /usr/bin/composer install
15-
RUN vendor/bin/phing phar-nightly
16-
COPY build/out/phpdraft-nightly.phar /usr/local/bin/phpdraft
1724

18-
FROM php:8.1-cli-alpine
25+
COPY --from=composer /usr/bin/composer /usr/bin/composer
26+
RUN composer install
27+
RUN ./vendor/bin/phing phar
28+
RUN chmod +x /usr/local/bin/phpdraft
29+
30+
FROM php:8.3-cli-bullseye AS phpdraft
31+
1932
LABEL maintainer="Sean Molenaar [email protected]"
20-
RUN apk add --no-cache gcc
21-
COPY --from=drafter /usr/local/bin/drafter /usr/local/bin/drafter
22-
COPY --from=build /usr/local/bin/phpdraft /usr/local/bin/phpdraft
23-
ENTRYPOINT /usr/local/bin/phpdraft -f /tmp/drafter/full_test.apib
33+
34+
COPY --from=phpdraft-build /usr/src/phpdraft/build/out/phpdraft-2.*.phar /usr/local/bin/phpdraft
35+
COPY --from=drafter-build /usr/local/bin/drafter /usr/local/bin/drafter
36+
37+
RUN ls -al /usr/local/bin/phpdraft
38+
39+
CMD phpdraft

0 commit comments

Comments
 (0)