diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 73462a5..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.5.1 diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml new file mode 100644 index 0000000..6e4a2be --- /dev/null +++ b/.semaphore/semaphore.yml @@ -0,0 +1,101 @@ +version: v1.0 +name: Rails Base API + +agent: + machine: + type: e1-standard-4 + os_image: ubuntu1804 + +execution_time_limit: + hours: 1 + +auto_cancel: + queued: + when: "true" + +fail_fast: + stop: + when: "true" + +blocks: + - name: Build + task: + secrets: + - name: docker-secrets + + prologue: + commands: + # Setup dynamic environment variables b/c they do not support via env_vars yet + - export BUNDLE_WITHOUT="development staging production" + - export DOCKER_REPO="flatstack/rails_base_api" + - export CACHE_IMAGE="${DOCKER_REPO}:${SEMAPHORE_GIT_BRANCH}" + - export WORKFLOW_CACHE_IMAGE="${CACHE_IMAGE}-${SEMAPHORE_WORKFLOW_ID}" + + # Authenticate with DockerHub + - echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin + + jobs: + - name: Docker build + commands: + - checkout + + # Try to pull image for this branch + - docker pull "${CACHE_IMAGE}" || true + + # Build image + - docker-compose build + + # Push image to DockerHub for the next tasks + - docker tag rails_base_api:latest "${WORKFLOW_CACHE_IMAGE}" + - docker push "${WORKFLOW_CACHE_IMAGE}" + + # Push images for the next builds + - docker tag rails_base_api:latest "${CACHE_IMAGE}" + - docker push "${CACHE_IMAGE}" + + - name: Run + task: + secrets: + - name: docker-secrets + + prologue: + commands: + # Setup dynamic environment variables b/c they do not support via env_vars yet + - export BUNDLE_WITHOUT="development staging production" + - export DOCKER_REPO="flatstack/rails_base_api" + - export CACHE_IMAGE="${DOCKER_REPO}:${SEMAPHORE_GIT_BRANCH}" + - export WORKFLOW_CACHE_IMAGE="${CACHE_IMAGE}-${SEMAPHORE_WORKFLOW_ID}" + + - checkout + + # Authenticate with DockerHub + - echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin + + # Pull image build on previous task + - docker pull "${WORKFLOW_CACHE_IMAGE}" + - docker tag "${WORKFLOW_CACHE_IMAGE}" rails_base_api:latest + + # Setup dotenv + - cp .env.example .env + + # Fix Semaphore permissions bug + - sudo chown 1000:1000 -R ./ + + # Run container + - docker-compose up --detach + + # Setup database + - docker-compose exec app bin/rails db:create db:schema:load + + jobs: + - name: Check Running Images + commands: + - docker ps + + - name: Run RSpec + commands: + - docker-compose exec app bin/rspec spec + + - name: Run Quality + commands: + - docker-compose exec app bin/quality diff --git a/docker-compose.yml b/docker-compose.yml index 1522a31..0f0d993 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,8 @@ services: - MAILER_SENDER_ADDRESS build: context: . + cache_from: + - ${CACHE_IMAGE} args: - ADDITIONAL_PACKAGES=build-base git - BUNDLE_WITHOUT="${BUNDLE_WITHOUT}"