diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 0000000..104293f --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,8 @@ +FROM php:8.2-cli-alpine + +COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ +RUN install-php-extensions zlib bcmath + +COPY builds/dime /docker/dime + +ENTRYPOINT ["/docker/dime"] \ No newline at end of file diff --git a/.docker/dime.sh b/.docker/dime.sh new file mode 100755 index 0000000..b1e6695 --- /dev/null +++ b/.docker/dime.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +if ! command -v docker >/dev/null 2>&1; then + echo + echo "Please check that Docker is correctly installed https://www.docker.com" + echo + exit 1 +fi + +if [[ "$1" == "delete" ]]; then + docker rmi -f ghcr.io/osteel/dime + rm -- "$0" + exit 0 +fi + +if ! [ -f "~/.dime/database.sqlite" ]; then + mkdir -p ~/.dime && touch ~/.dime/database.sqlite +fi + +command="docker run -it --rm -v ~/.dime/database.sqlite:/root/.dime/database.sqlite" + +if [[ "$1" == "process" && -n "$2" && -f "$2" ]]; then + filename=$(basename "$2") + path=$(cd $(dirname $2); pwd)/$filename + command+=" -v $path:/tmp/$filename ghcr.io/osteel/dime:latest process /tmp/$filename" +else + command+=" ghcr.io/osteel/dime:latest ${@:1}" +fi + +eval "$command" \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 105ebb0..bc1277f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ * text=auto eol=lf +/.docker export-ignore /.github export-ignore /app export-ignore /bootstrap export-ignore diff --git a/release.php b/.github/release.php similarity index 100% rename from release.php rename to .github/release.php diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 41dee79..f3eea83 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,15 +2,16 @@ name: Release on: push: - tags: ["*"] + tags: ["v*"] env: APP_ENV: "local" + REGISTRY: "ghcr.io" jobs: - build: - name: Build + phar: + name: Phar runs-on: ubuntu-latest steps: @@ -41,10 +42,37 @@ jobs: generate_release_notes: true - name: Update README - run: "php release.php ${{ github.ref_name }}" + run: "php .github/release.php ${{ github.ref_name }}" - name: Push changes uses: stefanzweifel/git-auto-commit-action@v4 with: - branch: main - commit_message: "Updated README" \ No newline at end of file + commit_message: "Updated README" + + docker: + name: Docker + needs: phar + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Log into registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_TOKEN }} + + - name: Set up Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: .docker/Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ env.REGISTRY }}/${{ github.repository }}:latest \ No newline at end of file diff --git a/README.md b/README.md index a3bb983..4bb11a3 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ You should seek the advice of a professional accountant before using this progra * [Installation](#installation) * [Composer](#composer) * [PHAR (Linux / Unix / macOS)](#phar-linux--unix--macos) + * [Docker](#docker) * [Usage](#usage) * [Spreadsheet format](#spreadsheet-format) * [Date](#date) @@ -57,11 +58,11 @@ You should seek the advice of a professional accountant before using this progra ## Installation -> **Note** -> Dime requires PHP 8.2 and the [BCMath](https://www.php.net/manual/en/book.bc.php) extension. - ### Composer +> **Note** +> Requires [Composer](https://getcomposer.org/) as well as PHP 8.2 and the [BCMath](https://www.php.net/manual/en/book.bc.php) extension. + You can instal Dime via [Composer](https://getcomposer.org): ``` @@ -92,8 +93,11 @@ $ source ~/.bash_profile ### PHAR (Linux / Unix / macOS) +> **Note** +> Requires PHP 8.2 and the [BCMath](https://www.php.net/manual/en/book.bc.php) extension. + -[Download the PHAR archive](https://github.com/osteel/dime/releases/download/v0.1.1/dime) from the [latest release](https://github.com/osteel/dime/releases/tag/v0.1.1). +[Download the PHAR archive](https://github.com/osteel/dime/releases/download/v0.1.2/dime) from the [latest release](https://github.com/osteel/dime/releases/tag/v0.1.2). You can use the application straight away: @@ -102,7 +106,7 @@ You can use the application straight away: $ php dime ``` -But you may want to move it to a directory that is in your system's `PATH`: +Or you may want to move it to a directory that is in your system's `PATH`: ``` $ chmod +x dime @@ -111,6 +115,28 @@ $ mv dime /usr/local/bin/dime You can now run `dime` from anywhere instead of `php dime`. +### Docker + +> **Note** +> Requires [Docker](https://www.docker.com/) and sh or Bash. + +[Download this shell script](/.docker/dime.sh) and use it straight away: + +``` +$ sh dime.sh +``` + +It will download Dime's [Docker image](https://github.com/users/osteel/packages/container/package/dime) and pass on commands to it. + +You may also want to move the script to a directory that is in your system's `PATH`: + +``` +$ chmod +x dime.sh +$ mv dime.sh /usr/local/bin/dime +``` + +You can now run `dime` from anywhere. + ## Usage You can display Dime's help menu by calling the executable without arguments: @@ -398,6 +424,12 @@ If you have installed Dime by downloading the [PHAR archive](#phar-linux--unix-- $ dime self-update ``` +If you have installed Dime via [Docker](#docker): + +``` +$ docker pull ghcr.io/osteel/dime:latest +``` + ### Delete If you have installed Dime [via Composer](#composer): @@ -412,7 +444,13 @@ If you have installed Dime by downloading the [PHAR archive](#phar-linux--unix-- $ rm /usr/local/bin/dime ``` -**In both cases**, you also need to delete the `.dime` folder (that contains the database): +If you have installed Dime via [Docker](#docker): + +``` +$ dime delete +``` + +**In all cases**, you also need to delete the `.dime` folder (unless you want to keep the database): ``` $ rm -r ~/.dime diff --git a/app/Commands/Delete.php b/app/Commands/Delete.php new file mode 100644 index 0000000..e790248 --- /dev/null +++ b/app/Commands/Delete.php @@ -0,0 +1,29 @@ +