cleanup directory strucutre and fine tune

This commit is contained in:
Joe Tretter
2022-09-30 10:55:07 -05:00
parent dae7fbc9e7
commit 9b25fa2eda
19 changed files with 69 additions and 27 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,4 @@
dataDir/*
app/dataDir/*
# Local .terraform directories
**/.terraform/*
@@ -30,3 +30,4 @@ override.tf.json
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
dumbserver.image.tar

24
README
View File

@@ -3,19 +3,35 @@ The Terraform part is on the more "enterprise" side with not only just a public
for the docker imaging look at: https://www.fosstechnix.com/how-to-create-docker-image-for-node-js-application/
The docker image can be built with
docker build -t dumbserver .
podman build -t dumbserver .
the image then can be extracted with
docker image save -o dumbserver.image.tar dumbserver
podman image save -o dumbserver.image.tar dumbserver
on the target machine it can be imported with
docker image load -i dumbserer.image.tar
podman image load -i dumbserer.image.tar
and running a container with the image id done via:
docker run -p 1280:1280 dumbserver
podman run --name dumbserver -p 1280:1280 dumbserver
(Port 1280 is what it listens on)
updating the image from a local file (in podman):
podman pull oci-archive:/tmp/dumbserver.image.tar
then the container needs to be re-created... stop/rm/run
At this stage, terraform will create an ssh accessable server (key is in "terraformtest1.ppk") - tutorial used for that: https://medium.com/@hmalgewatta/setting-up-an-aws-ec2-instance-with-ssh-access-using-terraform-c336c812322f
As part of the terraform, I copy a script to install docker/podman - and upload the image
then I set up the container and start it. that's it.
initialize with
terraform init
then plan
terraform plan
then apply
terraform apply
To read the terraform output into powershell use
$Json_Output = (& terraform output -json) | ConvertFrom-Json

View File

@@ -4,12 +4,15 @@ FROM node:current-slim
WORKDIR /nodejsapp
# To Install All dependencies
COPY package*.json ./
COPY package*.json .
RUN npm install
# To copy all application packages
COPY . .
# expose the data dir as a volume
VOLUME [ "dataDir" ]
# Expose port 1280 and Run the server.js file to start node js application
EXPOSE 1280
CMD [ "node", "dumbserver.js" ]

9
app/index.html Normal file
View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
Dumbserver
</head>
<body>
<p>Server version: 2022-09-30_10_21_17</p>
</body>
</html>

2
docker/buildimage.cmd Normal file
View File

@@ -0,0 +1,2 @@
docker build -t dumbserver ../app/
docker image save -o dumbserver.image.tar dumbserver

Binary file not shown.

View File

@@ -1,8 +0,0 @@
<!doctype html>
<html>
<head>
</head>
<body>
<p>Hello World!</p>
</body>
</html>

View File

@@ -1,11 +0,0 @@
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt -y update
apt -y upgrade
apt -y update
apt -y install docker.io
docker image load -i /tmp/dumbserver.image.tar
docker run -d -p 1280:1280 dumbserver

View File

@@ -44,16 +44,21 @@ resource "aws_instance" "app_server" {
# Uplaod docker image
provisioner "file" {
source = "dumbserver.image.tar"
source = "../docker/dumbserver.image.tar"
destination = "/tmp/dumbserver.image.tar"
}
# Upload example data file
provisioner "file" {
source = "../app/dataDir/data"
destination = "/tmp/data"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/setupAppServer.sh",
"sudo /tmp/setupAppServer.sh"
]
}
}

View File

@@ -0,0 +1,25 @@
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt -y update
apt -y upgrade
apt -y update
apt -y install podman
podman image load -i /tmp/dumbserver.image.tar
# create the directory for the data file and, if not existing (which is the default) copy the example file
mkdir -p /var/local/dumbserver
if [ ! -f /var/local/dumbserver/data ]; then
cp /tmp/data /var/local/dumbserver/
fi
podman run --name dumbserver -d -p 1280:1280 -v /var/local/dumbserver:/nodejsapp/dataDir dumbserver
# make sure it comes up after reboot...
podman generate systemd --new --name dumbserver > /etc/systemd/system/dumbserver-podman.service
systemctl daemon-reload
systemctl enable dumbserver-podman.service
# finally, all is set up and after all the updates we want to reboot into the new kernel version
shutdown -r 1