Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Nov 3, 2021
1 parent 4461a2e commit ee05733
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 33 deletions.
21 changes: 0 additions & 21 deletions Dockerfile

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<p align="center">
<img src="https://raw.githubusercontent.com/Clivern/Muffin/main/assets/logo.png?v=0.1.2" width="240" />
<img src="https://raw.githubusercontent.com/Clivern/Muffin/main/assets/logo.png?v=0.1.3" width="240" />
<h3 align="center">Muffin</h3>
<p align="center">Coding Playground Platform.</p>
<p align="center">
<a href="https://github.com/Clivern/Muffin/actions/workflows/build.yml">
<img src="https://github.com/Clivern/Muffin/actions/workflows/build.yml/badge.svg">
</a>
<a href="https://github.com/Clivern/Muffin/releases">
<img src="https://img.shields.io/badge/Version-0.1.2-red.svg">
<img src="https://img.shields.io/badge/Version-0.1.3-red.svg">
</a>
<a href="https://github.com/Clivern/Muffin/blob/master/LICENSE">
<img src="https://img.shields.io/badge/LICENSE-MIT-orange.svg">
<img src="https://img.shields.io/badge/LICENSE-MIT-cyan.svg">
</a>
</p>
</p>
Expand All @@ -20,7 +20,7 @@

### Getting Started

In order to run muffin, you need `ruby` `>=` `2.7.4` and `nodejs`. Then run the following commands:
In order to run `muffin`, you need `ruby` `>=` `2.7.4` and `nodejs`. Then run the following commands:

```zsh
$ gem install bundler
Expand Down
312 changes: 312 additions & 0 deletions app/helpers/snippet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#

module SnippetHelper
# Create a runner instance
def self.get_runner(language, local_path, version, slug, code)
if language == :python
return PythonRunner.new(local_path, version, slug, code)
end
end

# Python Runner
class PythonRunner
def initialize(local_path, version, slug, code)
@language = "python"
Expand Down Expand Up @@ -75,4 +77,314 @@ def run_script
attr_reader :slug
attr_reader :code
end

# Ruby Runner
class RubyRunner
def initialize(local_path, version, slug, code)
@language = "ruby"
@local_path = local_path
@version = version
@slug = slug
@code = code
end

# Build isolated environment
def isolate_environment
# Make directory
if !Dir.exists?("#{@local_path}/#{slug}")
Dir.mkdir("#{@local_path}/#{slug}")
end

# Create Dockerfile
if !File.exists?("#{@local_path}/#{slug}/Dockerfile")
dockerfile = "FROM #{@language}:#{@version}\n".dup
dockerfile << "RUN mkdir -p /etc/muffin\n"
dockerfile << "VOLUME /etc/muffin\n"
dockerfile << "CMD ['#{@language}']\n"

File.write("#{@local_path}/#{slug}/Dockerfile", dockerfile)
end

# Create code snippet
if !File.exists?("#{@local_path}/#{@slug}/script.py")
File.write("#{@local_path}/#{@slug}/script.py", @code)
end
end

# Build docker image
def build_image
# Build docker image
result = AwesomeSpawn.run("docker build . -t #{@language}:#{@version} -f #{@local_path}/#{slug}/Dockerfile")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while building docker image: #{result.error}"
end

result.output
end

# Run the code using the docker image
def run_script
result = AwesomeSpawn.run("docker run --rm -v #{@local_path}/#{slug}:#{@local_path}/#{slug} #{@language}:#{@version} #{@language} #{@local_path}/#{@slug}/script.py")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while running the script: #{result.error}"
end

result.output
end

attr_reader :local_path
attr_reader :version
attr_reader :slug
attr_reader :code
end

# PHP Runner
class PHPRunner
def initialize(local_path, version, slug, code)
@language = "php"
@local_path = local_path
@version = version
@slug = slug
@code = code
end

# Build isolated environment
def isolate_environment
# Make directory
if !Dir.exists?("#{@local_path}/#{slug}")
Dir.mkdir("#{@local_path}/#{slug}")
end

# Create Dockerfile
if !File.exists?("#{@local_path}/#{slug}/Dockerfile")
dockerfile = "FROM #{@language}:#{@version}\n".dup
dockerfile << "RUN mkdir -p /etc/muffin\n"
dockerfile << "VOLUME /etc/muffin\n"
dockerfile << "CMD ['#{@language}']\n"

File.write("#{@local_path}/#{slug}/Dockerfile", dockerfile)
end

# Create code snippet
if !File.exists?("#{@local_path}/#{@slug}/script.py")
File.write("#{@local_path}/#{@slug}/script.py", @code)
end
end

# Build docker image
def build_image
# Build docker image
result = AwesomeSpawn.run("docker build . -t #{@language}:#{@version} -f #{@local_path}/#{slug}/Dockerfile")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while building docker image: #{result.error}"
end

result.output
end

# Run the code using the docker image
def run_script
result = AwesomeSpawn.run("docker run --rm -v #{@local_path}/#{slug}:#{@local_path}/#{slug} #{@language}:#{@version} #{@language} #{@local_path}/#{@slug}/script.py")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while running the script: #{result.error}"
end

result.output
end

attr_reader :local_path
attr_reader :version
attr_reader :slug
attr_reader :code
end

# Java Runner
class JavaRunner
def initialize(local_path, version, slug, code)
@language = "java"
@local_path = local_path
@version = version
@slug = slug
@code = code
end

# Build isolated environment
def isolate_environment
# Make directory
if !Dir.exists?("#{@local_path}/#{slug}")
Dir.mkdir("#{@local_path}/#{slug}")
end

# Create Dockerfile
if !File.exists?("#{@local_path}/#{slug}/Dockerfile")
dockerfile = "FROM #{@language}:#{@version}\n".dup
dockerfile << "RUN mkdir -p /etc/muffin\n"
dockerfile << "VOLUME /etc/muffin\n"
dockerfile << "CMD ['#{@language}']\n"

File.write("#{@local_path}/#{slug}/Dockerfile", dockerfile)
end

# Create code snippet
if !File.exists?("#{@local_path}/#{@slug}/script.py")
File.write("#{@local_path}/#{@slug}/script.py", @code)
end
end

# Build docker image
def build_image
# Build docker image
result = AwesomeSpawn.run("docker build . -t #{@language}:#{@version} -f #{@local_path}/#{slug}/Dockerfile")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while building docker image: #{result.error}"
end

result.output
end

# Run the code using the docker image
def run_script
result = AwesomeSpawn.run("docker run --rm -v #{@local_path}/#{slug}:#{@local_path}/#{slug} #{@language}:#{@version} #{@language} #{@local_path}/#{@slug}/script.py")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while running the script: #{result.error}"
end

result.output
end

attr_reader :local_path
attr_reader :version
attr_reader :slug
attr_reader :code
end

# Golang Runner
class GolangRunner
def initialize(local_path, version, slug, code)
@language = "golang"
@local_path = local_path
@version = version
@slug = slug
@code = code
end

# Build isolated environment
def isolate_environment
# Make directory
if !Dir.exists?("#{@local_path}/#{slug}")
Dir.mkdir("#{@local_path}/#{slug}")
end

# Create Dockerfile
if !File.exists?("#{@local_path}/#{slug}/Dockerfile")
dockerfile = "FROM #{@language}:#{@version}\n".dup
dockerfile << "RUN mkdir -p /etc/muffin\n"
dockerfile << "VOLUME /etc/muffin\n"
dockerfile << "CMD ['#{@language}']\n"

File.write("#{@local_path}/#{slug}/Dockerfile", dockerfile)
end

# Create code snippet
if !File.exists?("#{@local_path}/#{@slug}/script.py")
File.write("#{@local_path}/#{@slug}/script.py", @code)
end
end

# Build docker image
def build_image
# Build docker image
result = AwesomeSpawn.run("docker build . -t #{@language}:#{@version} -f #{@local_path}/#{slug}/Dockerfile")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while building docker image: #{result.error}"
end

result.output
end

# Run the code using the docker image
def run_script
result = AwesomeSpawn.run("docker run --rm -v #{@local_path}/#{slug}:#{@local_path}/#{slug} #{@language}:#{@version} #{@language} #{@local_path}/#{@slug}/script.py")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while running the script: #{result.error}"
end

result.output
end

attr_reader :local_path
attr_reader :version
attr_reader :slug
attr_reader :code
end

# Rust Runner
class RustRunner
def initialize(local_path, version, slug, code)
@language = "rust"
@local_path = local_path
@version = version
@slug = slug
@code = code
end

# Build isolated environment
def isolate_environment
# Make directory
if !Dir.exists?("#{@local_path}/#{slug}")
Dir.mkdir("#{@local_path}/#{slug}")
end

# Create Dockerfile
if !File.exists?("#{@local_path}/#{slug}/Dockerfile")
dockerfile = "FROM #{@language}:#{@version}\n".dup
dockerfile << "RUN mkdir -p /etc/muffin\n"
dockerfile << "VOLUME /etc/muffin\n"
dockerfile << "CMD ['#{@language}']\n"

File.write("#{@local_path}/#{slug}/Dockerfile", dockerfile)
end

# Create code snippet
if !File.exists?("#{@local_path}/#{@slug}/script.py")
File.write("#{@local_path}/#{@slug}/script.py", @code)
end
end

# Build docker image
def build_image
# Build docker image
result = AwesomeSpawn.run("docker build . -t #{@language}:#{@version} -f #{@local_path}/#{slug}/Dockerfile")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while building docker image: #{result.error}"
end

result.output
end

# Run the code using the docker image
def run_script
result = AwesomeSpawn.run("docker run --rm -v #{@local_path}/#{slug}:#{@local_path}/#{slug} #{@language}:#{@version} #{@language} #{@local_path}/#{@slug}/script.py")

if result.exit_status != 0 || result.error != ""
raise Exception.new "Error while running the script: #{result.error}"
end

result.output
end

attr_reader :local_path
attr_reader :version
attr_reader :slug
attr_reader :code
end
end
8 changes: 0 additions & 8 deletions entrypoint.sh

This file was deleted.

0 comments on commit ee05733

Please sign in to comment.