Skip to content

Commit

Permalink
Merge branch 'master' into update-to-php-8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scottaubrey committed Nov 5, 2024
2 parents cfe0a18 + dc9cb34 commit 630d4c6
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 122 deletions.
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
COMPOSER_DEV_ARG=
IMAGE_TAG=develop
DATA_FOLDER=
67 changes: 67 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CI Pipeline

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
push:
branches:
- master

jobs:
generate-version:
runs-on: ubuntu-latest
outputs:
trunkver: ${{ steps.trunkver.outputs.trunkver }}
steps:
- name: Get a version tag
id: trunkver
uses: crftd-tech/trunkver@main
with:
prerelease: ${{ github.ref == 'refs/heads/master' && 'false' || 'true' }}
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Bring up test stack
run: docker compose up --wait
- name: Debug bring up test stack
if: failure()
run: docker compose logs
- name: Project Tests
run: docker compose exec app bash ./project_tests.sh
- name: Smoke Tests
run: docker compose exec app bash ./smoke_tests.sh
build-and-push:
needs: [generate-version, tests]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
env:
IMAGE_REPO: ghcr.io/elifesciences/api-dummy
IMAGE_TAG: ${{ github.ref == 'refs/heads/master' && needs.generate-version.outputs.trunkver || format('{0}-{1}', github.head_ref || github.ref_name, needs.generate-version.outputs.trunkver) }}
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push client image
uses: docker/build-push-action@v6
with:
push: true
load: false
# Disabled until elifesciences/php or another image with ARM support can be used as a base
# platforms: linux/amd64,linux/arm64
target: prod
tags: |
${{ env.IMAGE_REPO }}:${{ github.sha }}
${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}
31 changes: 27 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
ARG image_tag=latest
FROM elifesciences/api-dummy_composer:${image_tag} AS build
FROM ghcr.io/elifesciences/php:8.0-cli@sha256:f681973227dbab578218a98f252dfd36fd42016b74be6d0044221a7d8cdcc4e6
FROM composer:1.10 AS build

COPY composer.json composer.lock ./
RUN composer --no-interaction install --no-suggest --prefer-dist

FROM elifesciences/php_7.0_cli:656bb4bdf1e49a5e80337e2a7c4f44f10c3f52b0 AS base

USER elife

ENV PROJECT_FOLDER=/srv/api-dummy
RUN mkdir ${PROJECT_FOLDER}
WORKDIR ${PROJECT_FOLDER}

COPY --chown=elife:elife smoke_tests.sh ./
Expand All @@ -15,4 +18,24 @@ COPY --chown=elife:elife src/ src/

USER www-data
EXPOSE 8080

CMD ["php", "-S", "0.0.0.0:8080", "-t", "web/"]

FROM base AS prod

FROM base AS test

USER root
RUN mkdir -p build && chown www-data:www-data build

USER www-data
COPY --chown=elife:elife phpcs.xml.dist phpunit.xml.dist project_tests.sh ./
COPY --chown=elife:elife test/ test/

CMD ["./project_tests.sh"]

FROM test AS dev

COPY --from=build /usr/bin/composer /usr/bin/composer

CMD ["php", "-S", "0.0.0.0:8080", "-t", "web/"]
24 changes: 0 additions & 24 deletions Dockerfile.ci

This file was deleted.

13 changes: 0 additions & 13 deletions Dockerfile.composer

This file was deleted.

26 changes: 6 additions & 20 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ elifePipeline {
}

stage 'Build image', {
sh "IMAGE_TAG=${commit} docker-compose -f docker-compose.yml -f docker-compose.ci.yml build"
sh "IMAGE_TAG=${commit} docker-compose -f docker-compose.yml build"
image = DockerImage.elifesciences(this, 'api-dummy', commit)
elifePullRequestOnly { prNumber ->
// push immediately to allow downstream exploration even with automated tests failing
Expand All @@ -18,20 +18,20 @@ elifePipeline {
}

stage 'Project tests', {
dockerProjectTests 'api-dummy', commit
try {
sh "IMAGE_TAG=${commit} docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d"
sh "IMAGE_TAG=${commit} docker-compose -f docker-compose.yml -f docker-compose.ci.yml exec -T cli ./smoke_tests.sh"
sh "IMAGE_TAG=${commit} docker-compose -f docker-compose.yml up -d"
sh "IMAGE_TAG=${commit} docker-compose -f docker-compose.yml exec -T app ./project_tests.sh"
sh "IMAGE_TAG=${commit} docker-compose -f docker-compose.yml exec -T app ./smoke_tests.sh"
} finally {
sh 'docker-compose -f docker-compose.yml -f docker-compose.ci.yml down'
sh 'docker-compose -f docker-compose.yml down'
}
}

elifeMainlineOnly {
stage 'Push image', {
image.push()
}

stage 'Approval', {
elifeGitMoveToBranch commit, 'approved'
image.tag('approved').push()
Expand All @@ -40,18 +40,4 @@ elifePipeline {
},
'elife-libraries--ci'
)

elifeMainlineOnly {
stage 'Deploy on demo', {
checkout scm
elifeGitMoveToBranch commit, 'master'
elifeOnNode(
{
image.tag('latest').push()
},
'elife-libraries--ci'
)
builderDeployRevision 'api-dummy--demo', commit
}
}
}
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ eLife 2.0 Dummy API

This contains a dummy implementation of the [eLife 2.0 API](https://github.com/elifesciences/api-raml).

##Import article
## Import article

```$sh
cd /srv/api-dummy
./bin/import 09560
docker compose run app ./bin/import 09560
```

The above command should result in a data fixture for article 09560 being created at `/srv/api-dummy/data/articles/09560.json`
The above command should result in a data fixture for article 09560 being created at `data/articles/09560.json`

## Run locally

```$sh
cd /srv/api-dummy
php -S localhost:5001 ./web/index.php
docker compose up
```

Then visit [http://localhost:5001/articles](http://localhost:5001/articles) in your browser.
Then visit [http://localhost:8080/articles](http://localhost:8080/articles) in your browser.

## Update local vendor for development

```$sh
docker compose -f docker-compose.dev.yml run composer install
```

## Run tests

```$sh
docker compose run --rm app ./project_tests.sh
```
24 changes: 0 additions & 24 deletions docker-compose.ci.yml

This file was deleted.

10 changes: 10 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
composer:
build:
context: .
dockerfile: Dockerfile
target: build
volumes:
- ./composer.json:/app/composer.json
- ./composer.lock:/app/composer.lock
- ./vendor:/app/vendor
19 changes: 4 additions & 15 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
version: '3'

services:
composer:
volumes:
- ./composer.json:/app/composer.json
- ./composer.lock:/app/composer.lock
- vendor:/app/vendor
cli:
volumes:
- ./:/srv/api-dummy
- /srv/api-dummy/build
- vendor:/srv/api-dummy/vendor

volumes:
vendor:
app:
depends_on:
composer:
condition: service_completed_successfully
32 changes: 19 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
version: '3'

version: "2.4"
services:
composer:
build:
context: .
dockerfile: Dockerfile.composer
args:
composer_dev_arg: ${COMPOSER_DEV_ARG}
image: elifesciences/api-dummy_composer:${IMAGE_TAG}
command: /bin/bash
cli:
dockerfile: Dockerfile
target: build
command: install
volumes:
- ./composer.json:/app/composer.json
- ./composer.lock:/app/composer.lock
- vendor:/app/vendor

app:
build:
context: .
dockerfile: Dockerfile
args:
image_tag: ${IMAGE_TAG}
target: dev
image: elifesciences/api-dummy:${IMAGE_TAG:-dev}
environment:
DATA_FOLDER: ${DATA_FOLDER}
image: elifesciences/api-dummy:${IMAGE_TAG}
ports:
- "8080:8080"
depends_on:
- composer
volumes:
- ./:/srv/api-dummy
- /srv/api-dummy/build
- vendor:/srv/api-dummy/vendor

volumes:
vendor:

0 comments on commit 630d4c6

Please sign in to comment.