From e82caac2a770e28ab399971572bbc946c10e713b Mon Sep 17 00:00:00 2001 From: Michael Wagner Date: Thu, 19 Oct 2023 14:57:24 -0400 Subject: [PATCH] feat: earthfile built --- Earthfile | 145 +++++++++++++++++----------------- spec/integration/task_spec.cr | 70 ++++++++-------- 2 files changed, 106 insertions(+), 109 deletions(-) diff --git a/Earthfile b/Earthfile index 9469284a..d8defd81 100644 --- a/Earthfile +++ b/Earthfile @@ -2,44 +2,91 @@ VERSION 0.7 FROM 84codes/crystal:1.6.2-ubuntu-22.04 WORKDIR /workdir +# all runs all recipes +all: + WAIT + BUILD +lint + BUILD +specs + END + BUILD +task-spec + BUILD +integration-full-web-app + BUILD +integration-full-web-app-noauth + BUILD +integration-full-web-app-api + BUILD +integration-full-web-app-api-noauth + BUILD +integration-full-web-app-dir + # lint runs ameba code linter lint: FROM ghcr.io/crystal-ameba/ameba:1.5.0 COPY . ./ RUN ameba -deps: - COPY . ./ - RUN shards install - # specs runs unit tests specs: - FROM +deps + COPY . ./ + RUN shards install RUN crystal spec --tag "~integration" -integration-deps: - FROM +deps - RUN apt-get update \ - && apt-get install -y postgresql-client ca-certificates curl gnupg \ - && mkdir -p /etc/apt/keyrings \ - && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ - && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \ - && apt-get update \ - && apt-get install -y nodejs - RUN npm install --global yarn - RUN shards build --without-development - RUN cp bin/lucky /usr/bin/ - SAVE ARTIFACT ./bin/lucky - SAVE IMAGE lucky-cli:latest - -# integration-task-spec runs lucky command tests -integration-task-spec: - FROM +integration-deps +# task-spec runs lucky command tests +task-spec: + COPY +integration-base-image/lucky /usr/bin/lucky + COPY . ./ + RUN shards build lucky.hello_world --without-development ENV LUCKY_ENV=test ENV RUN_SEC_TESTER_SPECS=0 ENV RUN_HEROKU_SPECS=0 RUN crystal spec --tag task +# integration-full-web-app tests lucky full web app +integration-full-web-app: + FROM earthly/dind:alpine + COPY docker-compose.yml ./ + WITH DOCKER \ + --compose docker-compose.yml \ + --load lucky-image:latest=+integration-image + RUN docker run --network=host lucky-image:latest + END + +# integration-full-web-app-noauth tests lucky full web app with no auth +integration-full-web-app-noauth: + FROM earthly/dind:alpine + COPY docker-compose.yml ./ + WITH DOCKER \ + --compose docker-compose.yml \ + --load lucky-image:latest=+integration-image-noauth + RUN docker run --network=host lucky-image:latest + END + +# integration-full-web-app-api tests lucky full web app with api +integration-full-web-app-api: + FROM earthly/dind:alpine + COPY docker-compose.yml ./ + WITH DOCKER \ + --compose docker-compose.yml \ + --load lucky-image:latest=+integration-image-api + RUN docker run --network=host lucky-image:latest + END + +# integration-full-web-app-api-noauth tests lucky full web app with api and no auth +integration-full-web-app-api-noauth: + FROM earthly/dind:alpine + COPY docker-compose.yml ./ + WITH DOCKER \ + --compose docker-compose.yml \ + --load lucky-image:latest=+integration-image-api-noauth + RUN docker run --network=host lucky-image:latest + END + +# integration-full-web-app-dir tests lucky full web app in different directory +integration-full-web-app-dir: + FROM earthly/dind:alpine + COPY docker-compose.yml ./ + WITH DOCKER \ + --compose docker-compose.yml \ + --load lucky-image:latest=+integration-image-dir + RUN docker run --network=host lucky-image:latest + END + integration-base-image: RUN apt-get update \ && apt-get install -y postgresql-client ca-certificates curl gnupg \ @@ -53,7 +100,7 @@ integration-base-image: COPY --dir src ./ COPY --dir fixtures ./ COPY shard.yml ./ - RUN shards build --without-development + RUN shards build lucky --without-development RUN cp bin/lucky /usr/bin/ SAVE ARTIFACT ./bin/lucky WORKDIR /workdir @@ -118,53 +165,3 @@ integration-image-dir: RUN crystal run src/app.cr ENTRYPOINT ["crystal", "spec"] SAVE IMAGE lucky-image:dir - -# integration-full-web-app tests lucky full web app -integration-full-web-app: - FROM earthly/dind:alpine - COPY docker-compose.yml ./ - WITH DOCKER \ - --compose docker-compose.yml \ - --load lucky-image:latest=+integration-image - RUN docker run --network=host lucky-image:latest - END - -# integration-full-web-app-noauth tests lucky full web app with no auth -integration-full-web-app-noauth: - FROM earthly/dind:alpine - COPY docker-compose.yml ./ - WITH DOCKER \ - --compose docker-compose.yml \ - --load lucky-image:latest=+integration-image-noauth - RUN docker run --network=host lucky-image:latest - END - -# integration-full-web-app-api tests lucky full web app with api -integration-full-web-app-api: - FROM earthly/dind:alpine - COPY docker-compose.yml ./ - WITH DOCKER \ - --compose docker-compose.yml \ - --load lucky-image:latest=+integration-image-api - RUN docker run --network=host lucky-image:latest - END - -# integration-full-web-app-api-noauth tests lucky full web app with api and no auth -integration-full-web-app-api-noauth: - FROM earthly/dind:alpine - COPY docker-compose.yml ./ - WITH DOCKER \ - --compose docker-compose.yml \ - --load lucky-image:latest=+integration-image-api-noauth - RUN docker run --network=host lucky-image:latest - END - -# integration-full-web-app tests lucky full web app in different directory -integration-full-web-app-dir: - FROM earthly/dind:alpine - COPY docker-compose.yml ./ - WITH DOCKER \ - --compose docker-compose.yml \ - --load lucky-image:latest=+integration-image-dir - RUN docker run --network=host lucky-image:latest - END diff --git a/spec/integration/task_spec.cr b/spec/integration/task_spec.cr index d42fad8b..993d0cac 100644 --- a/spec/integration/task_spec.cr +++ b/spec/integration/task_spec.cr @@ -16,7 +16,7 @@ describe "Running a task", tags: ["integration", "task"] do input: IO::Memory.new("hello world"), output: io, env: { - "LUCKY_TASKS_FILE" => fixtures_tasks_path.to_s + "LUCKY_TASKS_FILE" => fixtures_tasks_path.to_s, } ) io.to_s.should eq("input: hello world\n") @@ -24,39 +24,39 @@ describe "Running a task", tags: ["integration", "task"] do end # TODO: test lucky command failures -#it "does not create project if directory with same name already exist" do - #FileUtils.mkdir "test-project" - #output = IO::Memory.new - #Process.run( - #"crystal run src/lucky.cr -- init.custom test-project", - #output: output, - #shell: true - #) - #message = "Folder named test-project already exists, please use a different name" - #output.to_s.strip.should contain(message) - #FileUtils.rm_rf "test-project" -#end +# it "does not create project if directory with same name already exist" do +# FileUtils.mkdir "test-project" +# output = IO::Memory.new +# Process.run( +# "crystal run src/lucky.cr -- init.custom test-project", +# output: output, +# shell: true +# ) +# message = "Folder named test-project already exists, please use a different name" +# output.to_s.strip.should contain(message) +# FileUtils.rm_rf "test-project" +# end -#it "does not create project if project name is not a valid project name" do - #output = IO::Memory.new - #Process.run( - #"crystal run src/lucky.cr -- init.custom 'test project'", - #env: ENV.to_h, - #output: output, - #shell: true - #) - #message = "Project name should only contain lowercase letters, numbers, underscores, and dashes." - #output.to_s.strip.should contain(message) -#end +# it "does not create project if project name is not a valid project name" do +# output = IO::Memory.new +# Process.run( +# "crystal run src/lucky.cr -- init.custom 'test project'", +# env: ENV.to_h, +# output: output, +# shell: true +# ) +# message = "Project name should only contain lowercase letters, numbers, underscores, and dashes." +# output.to_s.strip.should contain(message) +# end -#it "does not create project if the project name is reserved" do - #output = IO::Memory.new - #Process.run( - #"crystal run src/lucky.cr -- init.custom 'app'", - #env: ENV.to_h, - #output: output, - #shell: true - #) - #message = "Projects cannot be named app, app_database, app_server, shards, start_server." - #output.to_s.strip.should contain(message) -#end +# it "does not create project if the project name is reserved" do +# output = IO::Memory.new +# Process.run( +# "crystal run src/lucky.cr -- init.custom 'app'", +# env: ENV.to_h, +# output: output, +# shell: true +# ) +# message = "Projects cannot be named app, app_database, app_server, shards, start_server." +# output.to_s.strip.should contain(message) +# end