Add dockerfile build

This commit is contained in:
Brandon Thomas
2020-09-12 04:12:58 -04:00
parent d3d4ba2f66
commit 518a716c59
5 changed files with 115 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
.git
.idea/
target/
+22
View File
@@ -0,0 +1,22 @@
name: Publish Docker image to GitHub Package Registry
on: push
jobs:
build:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' # Only on master
steps:
- name: Copy Repo Files
uses: actions/checkout@master
#This Action Emits 2 Variables, IMAGE_SHA_NAME and IMAGE_URL
#which you can reference in subsequent steps
- name: Publish Docker Image to GPR
uses: machine-learning-apps/gpr-docker-publish@master
id: docker
with:
IMAGE_NAME: 'discord-vocodes'
DOCKERFILE_PATH: 'Dockerfile'
BUILD_CONTEXT: '.'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+41
View File
@@ -0,0 +1,41 @@
# Unsure if I want to create minimal images yet that run under Alpine Linux.
# I have instructions for that here: https://hub.docker.com/r/echelon/testcontainer/dockerfile
FROM ubuntu:xenial as build
WORKDIR /tmp
RUN apt-get update \
&& apt-get install -y \
build-essential \
curl \
libsodium-dev \
libssl-dev \
libssl1.0.0 \
pkg-config \
unzip \
wget
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- --default-toolchain stable -y
COPY Cargo.lock .
COPY Cargo.toml .
COPY src/ ./src
COPY script/ ./script
RUN $HOME/.cargo/bin/cargo fetch
#RUN $HOME/.cargo/bin/cargo build
RUN $HOME/.cargo/bin/cargo build --release
# Final image
FROM ubuntu:xenial
WORKDIR /
# SSL certs are required to make requests
COPY --from=build /etc/ssl /etc/ssl
# Shared libs are necessary
COPY --from=build /lib/x86_64-linux-gnu/libssl.so.1.0.0 /lib/x86_64-linux-gnu
COPY --from=build /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /lib/x86_64-linux-gnu
#COPY --from=build /tmp/target/debug/discord-vocodes /
COPY --from=build /tmp/target/release/discord-vocodes /
COPY --from=build /tmp/script /
CMD LD_LIBRARY_PATH=/usr/lib /discord-vocodes
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
# We can't run this as a CronJob since it isn't guaranteed to be scheduled
# to the same nodes. (Maybe there's a way for Kubernetes to do that?)
mkdir -p "${DOWNLOAD_DIR}"
mkdir -p "${TEMP_DIR}"
while :; do
./discord-vocodes
echo "Sleeping for ${SLEEP_TIMEOUT} seconds at $(date)"
sleep "${SLEEP_TIMEOUT}"
done
+36
View File
@@ -0,0 +1,36 @@
use hyper::Body;
use hyper::Client as HyperClient;
use hyper::Request;
use hyper_tls::HttpsConnector;
const VOCODES_SPEAK_ENDPOINT : &'static str = "http://mumble.stream/speak";
pub async fn fetch(text: &str, speaker: &str) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>> {
let mut request = format!("{{\"speaker\": \"{}\", \"text\": \"{}\"}}", speaker, text);
println!("Req: {}", request);
let https = HttpsConnector::new();
let client = HyperClient::builder()
.build::<_, hyper::Body>(https);
let req = Request::builder()
.uri(VOCODES_SPEAK_ENDPOINT)
.method("POST")
.header("Origin", "https://vo.codes")
.header("User-Agent", "Vocodes Discord Bot")
.header("Connection", "keep-alive")
.header("Content-Type", "application/json")
.body(Body::from(request))?;
let resp = client.request(req).await?;
println!("Status: {}", resp.status());
let bytes = hyper::body::to_bytes(resp.into_body()).await?;
let result = bytes.to_vec();
println!("Length: {}", result.len());
Ok(result)
}