Skip to content

Commit

Permalink
Merge pull request #192 from gordalina/sg/docker
Browse files Browse the repository at this point in the history
Add dockerfile
  • Loading branch information
gordalina committed Dec 11, 2021
2 parents a8c76f6 + 72fe199 commit dfa4ebd
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 17 deletions.
57 changes: 50 additions & 7 deletions .github/workflows/ci.yml
Expand Up @@ -87,6 +87,26 @@ jobs:
with:
fetch-depth: 0

- name: Get tag & commit hash
id: info
run: |
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
echo ::set-output name=COMMIT_SHA::$(git rev-parse --short HEAD)
echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup PHP
uses: shivammathur/setup-php@master
with:
Expand All @@ -107,18 +127,35 @@ jobs:
$(composer config home)/vendor/bin/box compile --config=box.gz.json
$(composer config home)/vendor/bin/box compile --config=box.bz2.json
- name: Tag
id: tag
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Build & tag image
uses: docker/build-push-action@v2
with:
build-args: |
BUILD_DATE=${{ steps.info.outputs.BUILD_DATE }}
CACHETOOL_VERSION=${{ steps.info.outputs.VERSION }}
COMMIT_SHA=${{ steps.info.outputs.COMMIT_SHA }}
PHP_VERSION=8.0
context: .
load: true
push: false
tags: |
gordalina/cachetool:latest
gordalina/cachetool:${{ steps.info.outputs.VERSION }}
ghcr.io/gordalina/cachetool:latest
ghcr.io/gordalina/cachetool:${{ steps.info.outputs.VERSION }}
- name: Push images
run: docker push gordalina/cachetool:${{ steps.info.outputs.VERSION }}
docker push ghcr.io/gordalina/cachetool:${{ steps.info.outputs.VERSION }}

- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: ${{ steps.tag.outputs.VERSION }}
tag_name: ${{ steps.tag.outputs.VERSION }}
name: ${{ steps.info.outputs.VERSION }}
tag_name: ${{ steps.info.outputs.VERSION }}
draft: false
prerelease: ${{ contains(github.ref, '-') }}
files: |
Expand All @@ -129,12 +166,18 @@ jobs:
LICENSE
body: |
## Changelog
The full changelog can be found in our [changelog file](https://github.com/gordalina/cachetool/blob/${{ steps.tag.outputs.VERSION }}/CHANGELOG.md)
The full changelog can be found in our [changelog file](https://github.com/gordalina/cachetool/blob/${{ steps.info.outputs.VERSION }}/CHANGELOG.md)
- name: Update GitHub Pages
if: ${{ !contains(github.ref, '-') }}
run: |
REF="${{ github.ref }}"
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
bin/update-gh-pages.sh ${{ steps.tag.outputs.VERSION }}
bin/update-gh-pages.sh ${{ steps.info.outputs.VERSION }}
- name: Push latest images
if: ${{ !contains(github.ref, '-') }}
run: |
docker push gordalina/cachetool:latest
docker push ghcr.io/gordalina/cachetool:latest
41 changes: 41 additions & 0 deletions Dockerfile
@@ -0,0 +1,41 @@
ARG PHP_VERSION

FROM php:${PHP_VERSION}-cli-alpine as build

ARG CACHETOOL_VERSION
ENV CACHETOOL_VERSION ${CACHETOOL_VERSION}

WORKDIR /opt/cachetool

RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet --install-dir=/usr/local/bin --filename=composer

RUN composer global config minimum-stability dev
RUN composer global config prefer-stable true
RUN composer global require humbug/box

COPY ./ ./
RUN composer install --prefer-dist
RUN $(composer config home)/vendor/bin/box compile --config=box.json

FROM php:${PHP_VERSION}-cli-alpine as runner

ARG CACHETOOL_VERSION
ARG COMMIT_SHA
ARG BUILD_DATE

LABEL org.opencontainers.image.title="CacheTool"
LABEL org.opencontainers.image.authors="https://github.com/gordalina/cachetool/graphs/contributors"
LABEL org.opencontainers.image.created="${BUILD_DATE}"
LABEL org.opencontainers.image.description="CLI App and library to manage apc & opcache"
LABEL org.opencontainers.image.documentation="https://github.com/gordalina/cachetool"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.ref.name="gordalina/cachetool"
LABEL org.opencontainers.image.revision="${COMMIT_SHA}"
LABEL org.opencontainers.image.source="https://github.com/gordalina/cachetool"
LABEL org.opencontainers.image.url="https://github.com/gordalina/cachetool"
LABEL org.opencontainers.image.vendor="gordalina"
LABEL org.opencontainers.image.version="${CACHETOOL_VERSION}"

COPY --from=build /opt/cachetool/cachetool.phar /usr/local/bin/cachetool

ENTRYPOINT [ "cachetool" ]
27 changes: 24 additions & 3 deletions README.md
Expand Up @@ -44,6 +44,10 @@ https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar.g
https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar.bz2
```

CacheTool is also packaged as a docker container available in [docker hub](https://hub.docker.com/r/gordalina/cachetool) and [github](https://github.com/gordalina/cachetool/pkgs/container/cachetool) container registries.

See below for [docker usage instructions](#usage-via-docker).

## Installation - old versions

Use tag name in the binary file name. E.g to download cachetool 3.2.2
Expand Down Expand Up @@ -133,18 +137,35 @@ You have some useful commands that you can use
## Usage via Docker
The great folks at @sbitio, namely @NITEMAN and @jonhattan wrote a docker image that you can invoke to run CacheTool. The images are hosted in https://hub.docker.com/r/sbitio/cachetool
Images are available in docker hub and github container registries:
- `gordalina/cachetool:latest`
- `ghcr.io/gordalina/cachetool:latest`
This is an example run with the `web` adapter:
```sh
APPDIR="/var/www/example.com"
DOCROOT="/var/www/example.com/current/web"
URL="http://example.com"
docker run --rm -v $APPDIR:$APPDIR -w $DOCROOT sbitio/cachetool cachetool --web --web-url=$URL [options] [arguments]

docker run --rm -v $APPDIR:$APPDIR -w $DOCROOT gordalina/cachetool cachetool --web --web-url=$URL [options] [arguments]
```
If the website is behind a proxy and/or load balancer you may want to ask directly the webserver instead of the public facing ip. Additionally, the webserver may be listening in another port. This is an example for running cachetool from the webserver host in such a setup:
```sh
DOMAIN="example.com"
PORT="8008"
APPDIR="/var/www/example.com"
DOCROOT="/var/www/example.com/current/web"
URL="http://$DOMAIN:$PORT"
docker run --rm --add-host $DOMAIN:172.17.0.1 -v $APPDIR:$APPDIR -w $DOCROOT sbitio/cachetool --web --web-url=$URL [options] [arguments]
```
Read more on their project page: https://github.com/sbitio/docker-cachetool
Thank you to @jonhattan and @NITEMAN for the [work with docker](https://github.com/sbitio/docker-cachetool).
## Configuration File
Expand Down
9 changes: 2 additions & 7 deletions composer.json
Expand Up @@ -12,7 +12,7 @@
"require": {
"hollodotme/fast-cgi-client": "^3.0",
"monolog/monolog": "^1.0|^2.0",
"php": "^7.3|^8.0",
"php": ">=8.0.0",
"psr/log": "^1.0",
"symfony/console": "^4.0|^5.0",
"symfony/dependency-injection": "^4.0|^5.0",
Expand Down Expand Up @@ -45,10 +45,5 @@
},
"bin": [
"bin/cachetool"
],
"config": {
"platform": {
"php": "8.0.0"
}
}
]
}

0 comments on commit dfa4ebd

Please sign in to comment.