Skip to content

Commit

Permalink
Merge pull request #40 from lolibrary/dev
Browse files Browse the repository at this point in the history
Dev env stetup!
  • Loading branch information
momijizukamori authored Aug 6, 2023
2 parents 356d7ac + dd95182 commit 41b4111
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev
1 change: 1 addition & 0 deletions .github/workflows/build-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches-ignore:
- 'master'
- 'i18n'
- 'dev'
jobs:
build-push-branch:
container:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and push dev image
on:
push:
branches:
- 'master'
- 'dev'
jobs:
build-push-dev:
container:
image: ghcr.io/lolibrary/builder
credentials:
username: ${{ github.actor }}
password: ${{ secrets.PAT }}
runs-on: ubuntu-latest
steps:
- name: Checkout build tools
uses: actions/checkout@v2
with:
repository: lolibrary/build
token: ${{ secrets.PAT }}
- name: Checkout Sakura
uses: actions/checkout@v2
with:
path: cache
- name: GHCR login
uses: docker/login-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.PAT }}
registry: ghcr.io
- name: Move fontfiles
run: cp fortawesome* cache/
- name: Docker Build & Push
run: |
docker build -t $DOCKER_SHA_TAG -t $DOCKER_LATEST_TAG --build-arg NOVA_USERNAME=${{ secrets.NOVA_USERNAME }} --build-arg NOVA_API_KEY=${{ secrets.NOVA_API_KEY }} -f cache/dev-dockerfile ./cache/
docker push $DOCKER_SHA_TAG
docker push $DOCKER_LATEST_TAG
env:
DOCKER_SHA_TAG: "ghcr.io/lolibrary/sakura-dev:${{ github.sha }}"
DOCKER_LATEST_TAG: "ghcr.io/lolibrary/sakura-dev:latest"

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Homestead.yaml
npm-debug.log
yarn-error.log
/.idea
fortawesome*
16 changes: 16 additions & 0 deletions dev-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM php:7.4-alpine

ARG NOVA_USERNAME
ARG NOVA_API_KEY

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
RUN apk add --no-cache curl nodejs npm bash \
&& install-php-extensions intl PDO_PGSQL

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /srv

COPY . /srv
RUN /srv/dev.sh "SETUP"
ENTRYPOINT [ "/bin/bash", "-c", "/srv/dev.sh" ]
24 changes: 24 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
cd /srv

if [[ "$1" == "SETUP" ]]; then
composer config http-basic.nova.laravel.com "$NOVA_USERNAME" "$NOVA_API_KEY" --no-interaction
COMPOSER_MEMORY_LIMIT=-1 composer install --no-interaction

cp fortawesome* ../
npm install
npm run development
else
npm install
npm run development

# PHP dev server doesn't have a way of handling a static folder seperately
# so just symlink these where the app expects them.
ln -s /srv/public/assets /srv/assets
ln -s /srv/public/fonts /srv/fonts
ln -s /srv/public/vendor /srv/vendor
ln -s /srv/public/images /srv/images
ln -s /srv/public/categories /srv/categories
php -S 0.0.0.0:3000 /srv/server.php
fi

2 changes: 2 additions & 0 deletions dev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
60 changes: 60 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This will set up the sakura web container and a postgres container it can connect to.
# The dev web container will run `npm install` and `npm run development` on startup, to pick up
# any changes to JS or SCSS files.

# If you are building the web container from scratch, you will need to provide the email address and
# license key for Nova, and put a Fontawesome tarball in the root directory (or supply a different way
# of accessing it or a replacement in package.json). These two components are propriety and we can't
# redistribute them, sorry!

# The db container uses mounted storage, so it's not necessary to rerun imports and migrations every time.
# Postgres will look in /dev/initdb the first time the container is started and run any sql or shell scripts in there.

version: "3"
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: lolibrary
POSTGRES_USER: postgres
POSTGRES_DB: library
PGDATA: /var/lib/postgresql/data/pgdata
ports:
- "8001:5432"
volumes:
- ./dev:/var/lib/postgresql/data:rw
- ./dev/initdb:/docker-entrypoint-initdb.d
web:
image: ghcr.io/lolibrary/sakura-dev:latest
# build:
# context: .
# dockerfile: ./dev-dockerfile
# args:
# NOVA_USERNAME: <email address for Nova license>
# NOVA_API_KEY: <key for Nova license>
environment:
- APP_DEBUG=true
- APP_KEY=insecurerandomkey111111111111111
- DB_CONNECTION=pgsql
- DB_DATABASE=library
- DB_USERNAME=postgres
- DB_PASSWORD=lolibrary
- DB_HOST=db
- AWS_DEFAULT_REGION=nyc3
- AWS_BUCKET=lolibrary
- AWS_URL="https://lolibrary.nyc3.digitaloceanspaces.com"
- AWS_CDN_URL="https://lolibrary.nyc3.cdn.digitaloceanspaces.com"
- APP_URL="http://0.0.0.0:3000"
- HTTPS_OFF=1
volumes:
- ./app:/srv/app
- ./database:/srv/database
- ./nova-components:/srv/nova-components
- ./resources:/srv/resources
- ./routes:/srv/routes
- ./tests:/srv/tests
ports:
- "3000:3000"
depends_on:
- db
6 changes: 4 additions & 2 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

$_ENV["HTTPS"] = "on";
$_SERVER["HTTPS"] = "on";
if (!getenv("HTTPS_OFF")) {
$_ENV["HTTPS"] = "on";
$_SERVER["HTTPS"] = "on";
}

/**
* Laravel - A PHP Framework For Web Artisans
Expand Down

0 comments on commit 41b4111

Please sign in to comment.