From 0b9f86013803110913ea51b6944bee21c496dcdc Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Tue, 23 Jun 2020 12:28:21 -0400 Subject: [PATCH 1/6] adding a docker-compose file for starting a server --- .env-example | 4 ++++ .gitignore | 1 + Dockerfile | 23 +++++++++++++++++++++++ docker-compose.yml | 14 ++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 .env-example create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env-example b/.env-example new file mode 100644 index 0000000..098bd89 --- /dev/null +++ b/.env-example @@ -0,0 +1,4 @@ +PORT=8080 +DOMAIN=example.com +ADMIN_USERNAME=username +ADMIN_PASSWORD=password diff --git a/.gitignore b/.gitignore index 2cffa58..075b932 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ expose.php database/expose.db .expose.php +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9cafe26 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM php:7.4-cli + +RUN apt-get update +RUN apt-get install -y git libzip-dev zip + +RUN docker-php-ext-install zip + +# Get latest Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +COPY . /src +WORKDIR /src + +# install the dependencies +RUN composer install -o --prefer-dist && chmod a+x expose + +ENV port=8080 +ENV domain=localhost +ENV username=username +ENV password=password +ENV exposeConfigPath=/src/config/expose.php + +CMD sed -i "s|username|${username}|g" ${exposeConfigPath} && sed -i "s|password|${password}|g" ${exposeConfigPath} && php expose serve ${domain} --port ${port} --validateAuthTokens diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ed34700 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.7" +services: + expose: + image: lukepolo/expose-server:latest + ports: + - 127.0.0.1:8080:${PORT} + environment: + port: ${PORT} + domain: ${DOMAIN} + username: ${ADMIN_USERNAME} + password: ${ADMIN_PASSWORD} + restart: always + volumes: + - ./database/expose.db:/root/.expose From 70a9666f375864cfc13b573799f4d225c933e15f Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Tue, 23 Jun 2020 12:37:15 -0400 Subject: [PATCH 2/6] Adding how to run with the readme --- docs/server/starting-the-server.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/server/starting-the-server.md b/docs/server/starting-the-server.md index 3e74c51..74970e5 100644 --- a/docs/server/starting-the-server.md +++ b/docs/server/starting-the-server.md @@ -122,4 +122,21 @@ return [ // ... ``` +## Running With Docker + +To run Expose with docker use the included `docker-compose.yaml`. Copy `.env-example` to `.env` and update the configuration. + +``` +PORT=8080 +DOMAIN=example.com +ADMIN_USERNAME=username +ADMIN_PASSWORD=password +``` + +After updating the environemtn variables you can start the server: + +```bash +docker-compose up -d +``` + Now that your basic expose server is running, let's take a look at how you can add SSL support. From b4379ddf6dbf24baeec5365640f6cea254e9ae24 Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Tue, 23 Jun 2020 12:44:56 -0400 Subject: [PATCH 3/6] Adding action to push docker image --- .github/workflows/docker-publish.yml | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..bb7a09e --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,70 @@ +name: Docker + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +env: + IMAGE_NAME: expose-server + +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + docker build . --file Dockerfile + + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + # Ensure test job passes before pushing image. + needs: test + + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION From b3f2edd18cbe84e1efacf2e6fc922f0ec18c8933 Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Tue, 23 Jun 2020 13:03:06 -0400 Subject: [PATCH 4/6] dont copy tests / .git --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..10ac9a8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +tests +.git From 3cb254e1f500a8046ffa095738a61b83f1c2705f Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Tue, 30 Jun 2020 14:32:47 -0400 Subject: [PATCH 5/6] Update starting-the-server.md --- docs/server/starting-the-server.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/server/starting-the-server.md b/docs/server/starting-the-server.md index 74970e5..8fdfe67 100644 --- a/docs/server/starting-the-server.md +++ b/docs/server/starting-the-server.md @@ -133,7 +133,7 @@ ADMIN_USERNAME=username ADMIN_PASSWORD=password ``` -After updating the environemtn variables you can start the server: +After updating the environment variables you can start the server: ```bash docker-compose up -d From 096a2b2a70249c7fbe83c3acde6424692ec6608a Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Wed, 1 Jul 2020 11:59:53 -0400 Subject: [PATCH 6/6] Simplified based on githubs docs https://docs.github.com/en/actions/language-and-framework-guides/publishing-docker-images --- .github/workflows/docker-publish.yml | 81 ++++++---------------------- 1 file changed, 15 insertions(+), 66 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index bb7a09e..aa1c4c4 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,70 +1,19 @@ -name: Docker - +name: Publish Docker image on: - push: - # Publish `master` as Docker `latest` image. - branches: - - master - - # Publish `v1.2.3` tags as releases. - tags: - - v* - - # Run tests for any PRs. - pull_request: - -env: - IMAGE_NAME: expose-server - + release: + types: [published] jobs: - # Run tests. - # See also https://docs.docker.com/docker-hub/builds/automated-testing/ - test: + push_to_registry: + name: Push Docker image to GitHub Packages runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Run tests - run: | - docker build . --file Dockerfile - - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - # Ensure test job passes before pushing image. - needs: test - - runs-on: ubuntu-latest - if: github.event_name == 'push' - - steps: - - uses: actions/checkout@v2 - - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME - - - name: Log into registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "master" ] && VERSION=latest - - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - name: Check out the repo + uses: actions/checkout@v2 + - name: Push to GitHub Packages + uses: docker/build-push-action@v1 + with: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: docker.pkg.github.com + repository: beyondcode/expose/expose-server + tag_with_ref: true