diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a19e0ba --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,29 @@ +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 + + - 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..1393084 --- /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..465cc86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,8 @@ COPY . /rails # Entrypoint prepares the database. RUN chmod +x ./bin/docker-entrypoint RUN chmod +x ./bin/rails +# USER root +# RUN chown -R rails:rails /rails/tmp /rails/log ENTRYPOINT ["./bin/docker-entrypoint"] # Precompile bootsnap code for faster boot times @@ -40,9 +42,9 @@ RUN apt-get update -qq && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Run and own only the runtime files as a non-root user for security -RUN useradd rails --create-home --shell /bin/bash && \ - chown -R rails:rails db log storage tmp -USER rails:rails +# RUN useradd rails --create-home --shell /bin/bash && \ +# chown -R rails:rails db log storage tmp +# USER rails:rails # Start the server by default, this can be overwritten at runtime EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml index 8526ff5..8b46441 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,14 +8,14 @@ services: - .:/rails ports: - "8000:80" - depends_on: - - db + # depends_on: + # - db environment: SECRET_KEY_BASE: secret - db: - image: postgres - volumes: - - ./tmp/db:/var/lib/postgresql/data - environment: - POSTGRES_PASSWORD: password + # db: + # image: postgres + # volumes: + # - ./tmp/db:/var/lib/postgresql/data + # environment: + # POSTGRES_PASSWORD: password