From 34582cfa6fe6f677782059cdc2b35fb7cb15f3f3 Mon Sep 17 00:00:00 2001 From: Angelo Dini Date: Wed, 24 Apr 2024 00:08:30 +0200 Subject: [PATCH] feat: add testing workflow --- .github/workflows/build.yml | 34 +++++++++++++++++++++++++ .github/workflows/deploy.yml | 40 ++++++++++++++++++++++++++++++ Dockerfile | 2 +- config/environments/development.rb | 3 ++- docker-compose.yml | 2 +- 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a4f66f4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build template + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build docker image + run: docker compose build + + - name: Run docker container + run: docker compose up -d + + - name: Check docker logs + run: | + docker ps + docker compose logs web + + - name: Test if service is reachable + run: | + sleep 30 + curl -v -s --retry 10 --retry-connrefused http://localhost:8000/ + + - name: Report error to Sentry + if: failure() + run: | + curl -sL https://sentry.io/get-cli/ | bash + export SENTRY_DSN=${{ secrets.SENTRY_DSN }} + MESSAGE_HEAD='Template: "${{ github.workflow }}" failed in ${{ github.repository }}.' + MESSAGE_BODY='Check for more details.' + sentry-cli send-event -m "$MESSAGE_HEAD" -m "$MESSAGE_BODY" --log-level=error diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..b089eb0 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,40 @@ +name: Deploy template + +on: + push: + schedule: + - cron: "20 16 * * *" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install divio-cli + + - name: Deploy to Divio + run: | + divio login ${{ secrets.DIVIO_TOKEN }} + divio app deploy test --remote-id ${{ secrets.DIVIO_WEBSITE_ID }} --build-mode FORCE + + - name: Test if website is reachable + run: | + curl -v -s --retry 10 --retry-connrefused ${{ secrets.WEBSITE_URL }} + + - name: Report error to Sentry + if: failure() + run: | + curl -sL https://sentry.io/get-cli/ | bash + export SENTRY_DSN=${{ secrets.SENTRY_DSN }} + MESSAGE_HEAD='Template: "${{ github.workflow }}" failed in ${{ github.repository }}.' + MESSAGE_BODY='Check for more details.' + sentry-cli send-event -m "$MESSAGE_HEAD" -m "$MESSAGE_BODY" --log-level=error diff --git a/Dockerfile b/Dockerfile index 161b73c..3359828 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,4 +46,4 @@ USER rails:rails # Start the server by default, this can be overwritten at runtime EXPOSE 80 -CMD ["./bin/rails", "server", "-p", "80", "-b", "0.0.0.0"] +CMD ["bundle", "exec", "rais", "server", "-p", "80", "-b", "0.0.0.0"] diff --git a/config/environments/development.rb b/config/environments/development.rb index a12f9cb..e3cb86e 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -76,6 +76,7 @@ # Divio Cloud config config.hosts = [ - /.*\.aldryn\.io/ + /.*\.aldryn\.io/, + 'localhost:8000', ] end diff --git a/docker-compose.yml b/docker-compose.yml index 8526ff5..5ae83be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: "3" services: web: build: . - command: ./bin/rails server -e development -b 0.0.0.0 -p 80 + command: bundle exec rails server -p 80 -b 0.0.0.0 volumes: - .:/rails ports: