Skip to content

Commit

Permalink
feat: earthfile built
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwagner committed Oct 19, 2023
1 parent 6425c6f commit e82caac
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 109 deletions.
145 changes: 71 additions & 74 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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
70 changes: 35 additions & 35 deletions spec/integration/task_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,47 @@ 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")
end
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

0 comments on commit e82caac

Please sign in to comment.