Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to help with docker #191

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Dockerfile → .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
WORKDIR /go/src/app

# Copy the current directory contents into the container at /go/src/app
COPY . .

# Remove Dockerfile to prevent issue with App Engine
RUN rm Dockerfile
COPY ../ .

# Expose port 8080 to the outside world
EXPOSE 8080
Expand Down
18 changes: 18 additions & 0 deletions .docker/docker-build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Description: Build docker image from Dockerfile

Write-Host "Building Docker image..."

# Confirm that the script is being executed from the correct directory
if (-not (Test-Path ".docker/docker-run.ps1")) {
Write-Host "You must run this command from the parent directory of this script."
exit
}

Write-Host "Confirmed that script is being executed from the correct directory."

$dockerCommand = "docker build --tag 'diplicity' ./.docker"

Write-Host "Running Docker command: $dockerCommand"

# Execute the Docker command
Invoke-Expression $dockerCommand
19 changes: 19 additions & 0 deletions .docker/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Description: Build docker image from Dockerfile
echo "Building Docker image..."

# Confirm that the script is being executed from the correct directory
if [ ! -f ".docker/docker-run.sh" ]; then
echo "You must run this command from the parent directory of this script."
exit 1
fi

echo "Confirmed that script is being executed from the correct directory."

dockerCommand="docker build --tag 'diplicity' ./.docker"

echo "Running Docker command: $dockerCommand"

# Execute the Docker command
eval $dockerCommand
10 changes: 10 additions & 0 deletions .docker/docker-create-network.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Description: Create a new docker network called my-net

Write-Host "Creating Docker network..."

$dockerCommand = "docker network create -d bridge my-net"

Write-Host "Running Docker command: $dockerCommand"

# Execute the Docker command
Invoke-Expression $dockerCommand
11 changes: 11 additions & 0 deletions .docker/docker-create-network.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Description: Create a new docker network called my-net
echo "Creating Docker network..."

dockerCommand="docker network create -d bridge my-net"

echo "Running Docker command: $dockerCommand"

# Execute the Docker command
eval $dockerCommand
42 changes: 42 additions & 0 deletions .docker/docker-run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Ensure that this command is being called from the parent directory
# of the Dockerfile. This is necessary for the volume mapping to work
# correctly.

Write-Host "Running Docker container..."

# Confirm that the script is being executed from the correct directory
if (-not (Test-Path ".docker/docker-run.ps1")) {
Write-Host "You must run this command from the parent directory of this script."
exit
}

Write-Host "Confirmed that script is being executed from the correct directory."

# Base docker run command
$dockerCommand = "docker run"

# Mount a volume from the host machine to the container. This means
# that the container will have access to the files in the host machine
# and that changes made in the host machine will be reflected in the
# container.
$dockerCommand += " -v .:/go/src/app:ro" # Add volume mapping

# Specify the network that the container should be connected to. This
# is necessary for the Discord bot to be able to work correctly.
$dockerCommand += " --network my-net" # Specify the network

# Specify that the 8080 port should be exposed to the host machine. This
# is the port that the API application listens on.
$dockerCommand += " -p 8080:8080" # Map port 8080

# Specify that the 8000 port should be exposed to the host machine. This
# is the port that the admin application listens on.
$dockerCommand += " -p 8000:8000" # Map port 8000

# Specify the image that should be used to create the container. This
$dockerCommand += " diplicity"

Write-Host "Running Docker command: $dockerCommand"

# Execute the Docker command
Invoke-Expression $dockerCommand
44 changes: 44 additions & 0 deletions .docker/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Ensure that this command is being called from the parent directory
# of the Dockerfile. This is necessary for the volume mapping to work
# correctly.

echo "Running Docker container..."

# Confirm that the script is being executed from the correct directory
if [ ! -f ".docker/docker-run.sh" ]; then
echo "You must run this command from the parent directory of this script."
exit 1
fi

echo "Confirmed that script is being executed from the correct directory."

# Base docker run command
dockerCommand="docker run"

# Mount a volume from the host machine to the container. This means
# that the container will have access to the files in the host machine
# and that changes made in the host machine will be reflected in the
# container.
dockerCommand+=" -v .:/go/src/app:ro" # Add volume mapping

# Specify the network that the container should be connected to. This
# is necessary for the Discord bot to be able to work correctly.
dockerCommand+=" --network my-net" # Specify the network

# Specify that the 8080 port should be exposed to the host machine. This
# is the port that the API application listens on.
dockerCommand+=" -p 8080:8080" # Map port 8080

# Specify that the 8000 port should be exposed to the host machine. This
# is the port that the admin application listens on.
dockerCommand+=" -p 8000:8000" # Map port 8000

# Specify the image that should be used to create the container.
dockerCommand+=" diplicity"

echo "Running Docker command: $dockerCommand"

# Execute the Docker command
eval $dockerCommand
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ game/game.debug

# Diff tool files
*.orig

.env
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ To enable debugging the JSON output in a browser, adding the query parameter `ac

- Download Docker
- Navigate to the root directory of this project
- Run `docker build --tag 'diplicity' .`
- Run `docker run -p 8080:8080 -p 8000:8000 diplicity`
- Use `ps1` files for Windows and `sh` files for UNIX
- Run `.\.docker\docker-build.ps1` **or** `.\.docker\docker-build.sh` (only required once)
- Run `.\.docker\docker-network.ps1` **or** `.\.docker\docker-network.sh` (only required once)
- Run `.\.docker\docker-run.ps1` **or** `.\.docker\docker-run.sh`
- The API is now available on your machine at `localhost:8080`
- The Admin server is now available on your machine at `localhost:8000`

Expand Down
Loading