From d1f4af9a0e281b3164c1bdf7e21ebdd96818e566 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Sun, 6 Aug 2023 11:09:01 -0400 Subject: [PATCH 1/3] Add setup for dev env - Add dockerfile for building dev images - Add github actions workflow for building dev images - Add change to index.php to allow creation of HTTPS routes to be toggled - Add docker-compose file for dev setup --- .dockerignore | 1 + .github/workflows/build-dev.yml | 40 +++++++++++++++++ .gitignore | 1 + dev-dockerfile | 16 +++++++ dev.sh | 24 ++++++++++ dev/.gitignore | 2 + docker-compose.yml | 77 +++++++++++++++++++++++++++++++++ public/index.php | 6 ++- 8 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100755 .github/workflows/build-dev.yml create mode 100644 dev-dockerfile create mode 100755 dev.sh create mode 100755 dev/.gitignore create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..90012116 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +dev \ No newline at end of file diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml new file mode 100755 index 00000000..9ba57b9f --- /dev/null +++ b/.github/workflows/build-dev.yml @@ -0,0 +1,40 @@ +name: Build and push branch image +on: + push: + branches: + - 'master' + - 'dockerize' +jobs: + build-push-branch: + 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_LATEST_TAG + env: + DOCKER_SHA_TAG: "ghcr.io/lolibrary/sakura-dev:${{ github.sha }}" + DOCKER_LATEST_TAG: "ghcr.io/lolibrary/sakura-dev:latest" + diff --git a/.gitignore b/.gitignore index c57824bb..65096a5d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Homestead.yaml npm-debug.log yarn-error.log /.idea +fortawesome* diff --git a/dev-dockerfile b/dev-dockerfile new file mode 100644 index 00000000..c50021d2 --- /dev/null +++ b/dev-dockerfile @@ -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" ] \ No newline at end of file diff --git a/dev.sh b/dev.sh new file mode 100755 index 00000000..e0270987 --- /dev/null +++ b/dev.sh @@ -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 + diff --git a/dev/.gitignore b/dev/.gitignore new file mode 100755 index 00000000..d6b7ef32 --- /dev/null +++ b/dev/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b08599c6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,77 @@ +# To run the Archive in docker for the first time you should run one of the init scripts: +# - linux: `script/docker/init.sh` +# - windows: `script/docker/init.cmd` +# +# This will handle setting up config files, creating databases, and running migrations. +# +# After these oneoff tasks have been performed, you can start the development +# webserver with the command: +# +# ``` +# docker-compose up -d web +# ``` +# +# Once it is running, it will be visible at http://localhost:3000/ +# +# To run tests, you should use the test container instead of the web container, +# because it includes a headless chrome container for running JS-based tests. +# You can run tests like this: +# +# ``` +# docker-compose run --rm test bundle exec cucumber features/other_a/autocomplete.feature +# ``` + +version: "3" +# volumes: +# my-datavolume: +# redis-data: +# esdata1: +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" + # command: + # [ + # "mysqld", + # "--sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION", + # ] + volumes: + - ./dev:/var/lib/postgresql/data:rw + - ./dev/initdb:/docker-entrypoint-initdb.d + web: + image: sakura + # build: + # context: . + # dockerfile: ./dev-dockerfile + 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 \ No newline at end of file diff --git a/public/index.php b/public/index.php index 59d22482..1661968a 100644 --- a/public/index.php +++ b/public/index.php @@ -1,7 +1,9 @@ Date: Sun, 6 Aug 2023 12:07:50 -0400 Subject: [PATCH 2/3] Push each tag seperately --- .github/workflows/build-dev.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index 9ba57b9f..8716cb36 100755 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -1,4 +1,4 @@ -name: Build and push branch image +name: Build and push dev image on: push: branches: @@ -33,7 +33,8 @@ jobs: - 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_LATEST_TAG + 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" From dd951826b72c0259553386fccb114e6eb2fd6ce2 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Sun, 6 Aug 2023 12:25:10 -0400 Subject: [PATCH 3/3] Clean up compose file a little --- .github/workflows/build-branch.yml | 1 + .github/workflows/build-dev.yml | 4 +-- docker-compose.yml | 47 ++++++++++-------------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-branch.yml b/.github/workflows/build-branch.yml index aa84de59..98877058 100755 --- a/.github/workflows/build-branch.yml +++ b/.github/workflows/build-branch.yml @@ -4,6 +4,7 @@ on: branches-ignore: - 'master' - 'i18n' + - 'dev' jobs: build-push-branch: container: diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index 8716cb36..ecfb5728 100755 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -3,9 +3,9 @@ on: push: branches: - 'master' - - 'dockerize' + - 'dev' jobs: - build-push-branch: + build-push-dev: container: image: ghcr.io/lolibrary/builder credentials: diff --git a/docker-compose.yml b/docker-compose.yml index b08599c6..640a8067 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,31 +1,16 @@ -# To run the Archive in docker for the first time you should run one of the init scripts: -# - linux: `script/docker/init.sh` -# - windows: `script/docker/init.cmd` -# -# This will handle setting up config files, creating databases, and running migrations. -# -# After these oneoff tasks have been performed, you can start the development -# webserver with the command: -# -# ``` -# docker-compose up -d web -# ``` -# -# Once it is running, it will be visible at http://localhost:3000/ -# -# To run tests, you should use the test container instead of the web container, -# because it includes a headless chrome container for running JS-based tests. -# You can run tests like this: -# -# ``` -# docker-compose run --rm test bundle exec cucumber features/other_a/autocomplete.feature -# ``` +# 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" -# volumes: -# my-datavolume: -# redis-data: -# esdata1: services: db: image: postgres @@ -37,19 +22,17 @@ services: PGDATA: /var/lib/postgresql/data/pgdata ports: - "8001:5432" - # command: - # [ - # "mysqld", - # "--sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION", - # ] volumes: - ./dev:/var/lib/postgresql/data:rw - ./dev/initdb:/docker-entrypoint-initdb.d web: - image: sakura + image: ghcr.io/lolibrary/sakura-dev:latest # build: # context: . # dockerfile: ./dev-dockerfile + # args: + # NOVA_USERNAME: + # NOVA_API_KEY: environment: - APP_DEBUG=true - APP_KEY=insecurerandomkey111111111111111