Merge pull request #37 from m3nu/main

Clean up Docker run.sh script, add GH Workflow for image updates
This commit is contained in:
corbpie 2022-03-14 21:15:52 +11:00 committed by GitHub
commit 2204970248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 8 deletions

38
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,38 @@
on:
# push:
# pull_request:
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate debugging enabled'
required: false
default: false
jobs:
build:
name: Build, push, and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup tmate debug session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
- name: Build container image
run: |
docker build \
--tag ghcr.io/cp6/my-idlers:$(echo $GITHUB_SHA | head -c7) \
--tag ghcr.io/cp6/my-idlers:latest \
.
- name: Container registry login
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
- name: Push image to GitHub
if: github.ref == 'refs/heads/main'
run: |
docker push ghcr.io/cp6/my-idlers:$(echo $GITHUB_SHA | head -c7)
docker push ghcr.io/cp6/my-idlers:latest

View File

@ -8,7 +8,7 @@ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN composer install && \ RUN composer install
cp .env.example .env
ENV APP_ENV production
ENTRYPOINT ["/app/run.sh"] ENTRYPOINT ["/app/run.sh"]

View File

@ -73,6 +73,19 @@ removed.
* Run `php artisan migrate:fresh --seed` to create tables and seed data * Run `php artisan migrate:fresh --seed` to create tables and seed data
* Run `php artisan serve` * Run `php artisan serve`
## Run using Docker
```
docker run \
-p 8000:8000\
-e APP_URL=https://... \
-e DB_HOST=... \
-e DB_DATABASE=... \
-e DB_USERNAME=... \
-e DB_PASSWORD=... \
ghcr.io/m3nu/my-idlers:latest # TODO: adjust after official image is set up!
docker exec ... php artisan migrate:fresh --seed --force # Set up database one time
```
## API endpoints ## API endpoints
For GET requests the header must have `Accept: application/json` and your API token (found at `/account`) For GET requests the header must have `Accept: application/json` and your API token (found at `/account`)

13
run.sh
View File

@ -1,7 +1,9 @@
#!/bin/sh #!/bin/sh
# TODO: global env vars aren't used. # Run setup only if .env file doesn't exist.
cat > /app/.env.production << EOF if [ ! -e .env.production ]
then
cat > .env.production << EOF
APP_NAME=MyIdlers APP_NAME=MyIdlers
APP_DEBUG=false APP_DEBUG=false
APP_KEY= APP_KEY=
@ -12,10 +14,9 @@ DB_DATABASE=${DB_DATABASE}
DB_USERNAME=${DB_USERNAME} DB_USERNAME=${DB_USERNAME}
DB_PASSWORD=${DB_PASSWORD} DB_PASSWORD=${DB_PASSWORD}
APP_URL=${APP_URL} APP_URL=${APP_URL}
ASSET_URL=${ASSET_URL}
EOF EOF
php artisan key:generate --no-interaction --force
fi
# TODO: only run this once # php artisan migrate:fresh --seed
php artisan key:generate
php artisan migrate:fresh --seed --force
php artisan serve --host=0.0.0.0 --port=8000 --env=production php artisan serve --host=0.0.0.0 --port=8000 --env=production