Skip to content

Commit

Permalink
Docker distribution (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
osteel authored Jun 26, 2023
1 parent 74e6d8f commit 18741c9
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 25 deletions.
8 changes: 8 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
30 changes: 30 additions & 0 deletions .docker/dime.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text=auto eol=lf

/.docker export-ignore
/.github export-ignore
/app export-ignore
/bootstrap export-ignore
Expand Down
File renamed without changes.
40 changes: 34 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
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
50 changes: 44 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):

```
Expand Down Expand Up @@ -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.
<!-- phar -->
[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).
<!-- /phar -->

You can use the application straight away:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions app/Commands/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Commands;

use LaravelZero\Framework\Commands\Command;

/** @codeCoverageIgnore */
class Delete extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'delete';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Delete Dime';

/** Execute the console command. */
public function handle(): int
{
return self::SUCCESS;
}
}
21 changes: 21 additions & 0 deletions app/Commands/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Commands;

final class Helpers
{
public static function installedViaComposer(): bool
{
return str_contains(__DIR__, '.composer/vendor');
}

public static function installedViaDocker(): bool
{
return str_contains(__DIR__, '/docker');
}

public static function installedViaPhar(): bool
{
return ! self::installedViaComposer() && ! self::installedViaDocker();
}
}
11 changes: 0 additions & 11 deletions app/Services/SelfUpdate/Helpers.php

This file was deleted.

Binary file modified builds/dime
Binary file not shown.
7 changes: 5 additions & 2 deletions config/commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use App\Services\SelfUpdate\Helpers;
use App\Commands\Helpers;

return [

Expand Down Expand Up @@ -107,9 +107,12 @@
LaravelZero\Framework\Commands\StubPublishCommand::class,
LaravelZero\Framework\Commands\TestMakeCommand::class,
] : [],
Helpers::installedViaComposer() ? [
Helpers::installedViaPhar() === false ? [
LaravelZero\Framework\Components\Updater\SelfUpdateCommand::class,
] : [],
Helpers::installedViaDocker() === false ? [
\App\Commands\Delete::class,
] : [],
),

];

0 comments on commit 18741c9

Please sign in to comment.