forked from zopanix/docker_factorio_server
-
Notifications
You must be signed in to change notification settings - Fork 248
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
Deploy to Fargate #227
Draft
rangerscience
wants to merge
1
commit into
factoriotools:master
Choose a base branch
from
rangerscience:fargate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Deploy to Fargate #227
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.terraform* | ||
terraform.tfstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM dtandersen/factorio:latest | ||
|
||
RUN apk add --update python py-pip | ||
RUN pip install awscli | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine those two run commands with |
||
|
||
COPY fargate-entrypoint.sh fargate-entrypoint.sh | ||
|
||
ENTRYPOINT ["/fargate-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# SIGTERM-handler | ||
term_handler() { | ||
if [ $pid -ne 0 ]; then | ||
aws s3 cp /factorio $STORAGE --recursive | ||
kill -SIGTERM "$pid" | ||
wait "$pid" | ||
fi | ||
exit 143; # 128 + 15 -- SIGTERM | ||
} | ||
|
||
trap 'kill ${!}; term_handler' SIGTERM | ||
|
||
# Load last saved game state | ||
aws s3 cp $STORAGE /factorio --recursive | ||
|
||
# run application | ||
./docker-entrypoint.sh & | ||
pid="$!" | ||
|
||
# save game state every five minutes | ||
while true | ||
do | ||
aws s3 cp /factorio $STORAGE --recursive | ||
sleep $AUTOSAVE_RATE | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
||
resource "aws_s3_bucket" "factorio" { | ||
bucket_prefix = "factorio-" | ||
versioning { | ||
enabled = true | ||
} | ||
} | ||
|
||
resource "aws_ecs_cluster" "factorio" { | ||
name = "factorio-ecs-cluster" | ||
} | ||
|
||
data "template_file" "factorio" { | ||
template = "${file("${path.module}/tasks/factorio.json")}" | ||
|
||
vars { | ||
image = "rangerscience/factorio:fargate" | ||
storage = "s3://${aws_s3_bucket.factorio.id}" | ||
autosave_rate = 300 # Seconds between saves to S3 | ||
} | ||
} | ||
|
||
resource "aws_ecs_task_definition" "factorio" { | ||
family = "factorio" | ||
container_definitions = "${data.template_file.factorio.rendered}" | ||
|
||
requires_compatibilities = ["FARGATE"] | ||
network_mode = "awsvpc" | ||
|
||
requires_compatibilities = ["FARGATE"] | ||
cpu = "4096" // 4 vCPU | ||
memory = "8192" // 8 GB (min for 4 vCPU) | ||
|
||
task_role_arn = "${aws_iam_role.factorio.arn}" | ||
} | ||
|
||
resource "aws_vpc" "main" { | ||
cidr_block = "10.0.0.0/16" | ||
} | ||
|
||
resource "aws_subnet" "factorio" { | ||
cidr_block = "10.0.1.0/26" | ||
vpc_id = "${aws_vpc.main.id}" | ||
} | ||
|
||
resource "aws_ecs_service" "factorio" { | ||
name = "factorio" | ||
launch_type = "FARGATE" | ||
cluster = "${aws_ecs_cluster.factorio.id}" | ||
task_definition = "${aws_ecs_task_definition.factorio.arn}" | ||
desired_count = 1 | ||
|
||
network_configuration { | ||
subnets = ["${aws_subnet.factorio.id}"] | ||
assign_public_ip = true | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "factorio" { | ||
name = "factorio" | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "ecs-tasks.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
data "aws_iam_policy_document" "factorio" { | ||
statement { | ||
sid = "1" | ||
actions = ["*"] | ||
resources = ["${aws_s3_bucket.factorio.arn}"] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "factorio" { | ||
policy = "${data.aws_iam_policy_document.factorio.json}" | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "factorio" { | ||
role = "${aws_iam_role.factorio.name}" | ||
policy_arn = "${aws_iam_policy.factorio.arn}" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove the empty file from git. :) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[ | ||
{ | ||
"name": "factorio", | ||
"environment": [ | ||
{ "name": "STORAGE", "value": "${storage}"}, | ||
{ "name": "AUTOSAVE_RATE", "value": "${autosave_rate}"} | ||
], | ||
"essential": true, | ||
"image": "${image}", | ||
"portMappings": [ | ||
{ | ||
"containerPort": 34197, | ||
"hostPort": 34197, | ||
"protocol": "udp" | ||
}, | ||
{ | ||
"containerPort": 27015, | ||
"hostPort": 27015, | ||
"protocol": "tcp" | ||
} | ||
] | ||
} | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not update any packages if it isn't necessary and you forgot two flags.
I would use
apk --no-cache --no-progress add py-pip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with APK (or APT, for that matter) but although there IS an APK awscli package, it's still unreleased (edge?) and I couldn't figure out how to install that instead. Otherwise, the python install of the AWS CLI is the simplest set of steps, even if it does balloon the image size :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is apk from Alpine and not apt from Debian :).
I was more nitpicking about the
--update
. I think it is fine to use the ``pip`´ variant but if you are interested you can find it here https://pkgs.alpinelinux.org/package/edge/testing/x86_64/aws-cli