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

dockerfile, docker-compose, and init.sh #16

Open
mabushey opened this issue Apr 13, 2023 · 0 comments
Open

dockerfile, docker-compose, and init.sh #16

mabushey opened this issue Apr 13, 2023 · 0 comments

Comments

@mabushey
Copy link

mabushey commented Apr 13, 2023

I made a docker config to automatically have my site in a container. I'd be happy to provide a PR, or you can take what I have here:

cat Dockerfile

FROM ubuntu:latest

WORKDIR /root

RUN apt-get update && apt-get install -y vim curl git && rm -rf /var/lib/apt

RUN curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash && mv ./spin /usr/local/bin/

RUN VERSION=$(curl -so- https://github.com/fermyon/bartholomew/releases | grep 'href="/fermyon/bartholomew/releases/tag/v[0-9]*.[0-9]*.[0-9]*\"' | sed -E 's/.*\/fermyon\/bartholomew\/releases\/tag\/(v[0-9\.]+)".*/\1/g' | head -1) && curl -fsOL "https://github.com/fermyon/bartholomew/releases/download/${VERSION}/bart-cli-${VERSION}-linux-amd64.tar.gz" && tar -xvzf bart-cli*.tar.gz && mv ./bart /usr/local/bin/ && rm bart-cli*.tar.gz 

EXPOSE 3000
COPY ./init.sh /root/init.sh
RUN chmod +x /root/init.sh
CMD /root/init.sh

cat docker-compose

version: '3.8'

services:
  bart:
    container_name: bart
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./ssh:/root/.ssh
    environment:
      - GIT_URL="git.sendthemtomir.com"
      - GIT_PORT=10022
      - GIT_REPO="/mbushey/bart-mir.git"
    ports:
      - "3000:3000"

cat init.sh

#!/bin/bash

if [ -z $GIT_URL ]; then
  export GIT_URL=github.com
  echo "ENV var GIT_URL not set. Setting to: '$GIT_URL'"
fi

if [ -z $GIT_PORT ]; then
  export GIT_PORT=22
  echo "ENV var GIT_PORT not set. Setting to: $GIT_PORT"
fi

if [ -z $GIT_REPO ]; then
  export GIT_REPO="/fermyon/bartholomew-site-template.git"
  echo "ENV var GIT_REPO not set. Setting to: '$GIT_REPO'"
fi

chmod 700 /root/.ssh
chmod 700 /root/.ssh/id_ed25519

if [ ! -f /root/.ssh/id_ed25519.pub ]; then
  echo "SSH key not found, generating"
  ssh-keygen -t ed25519 -C "bart" -f "/root/.ssh/id_ed25519" -q -N ""
  echo "Please add this key as a read-only deploy key to your git repo:"
  cat /root/.ssh/id_ed25519.pub
fi

## Recreate known_hosts ONLY if host does not exist in ~/.ssh/known_hosts
ssh-keygen -F "[${GIT_URL}]:${GIT_PORT}" || echo "Generating .ssh/known_hosts" && ssh-keyscan -p $GIT_PORT $GIT_URL > ~/.ssh/known_hosts

if [ ! -d bart ]; then
  git clone ssh://git@${GIT_URL}:${GIT_PORT}${GIT_REPO} bart
  if [ $? != 0 ]; then
    echo "Clone failed."
    echo "Make sure This key has perms to pull at $GIT_URL:"
    cat /root/.ssh/id_ed25519.pub
  fi
fi

cd bart
git pull
spin up --listen 0.0.0.0:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant