From a352341d3d55046792e3478784b32d76a4cb0ed4 Mon Sep 17 00:00:00 2001 From: Benjamin Sherriff Date: Thu, 6 Jul 2023 10:59:41 -0400 Subject: [PATCH] Fixed docker container linking --- .env.TEMPLATE | 4 ++-- .version | 2 +- Cargo.lock | 2 +- Cargo.toml | 4 +--- Dockerfile | 6 +++--- Makefile | 26 ++++++++++---------------- README.md | 6 +++--- docker-compose.yml | 17 ++++++++--------- 8 files changed, 29 insertions(+), 38 deletions(-) diff --git a/.env.TEMPLATE b/.env.TEMPLATE index 0289214..d789382 100644 --- a/.env.TEMPLATE +++ b/.env.TEMPLATE @@ -1,5 +1,5 @@ DISCORD_TOKEN= RUST_LOG=warn,siren=info -POSTGRES_USER= +POSTGRES_USER=siren POSTGRES_PASSWORD= -POSTGRES_DB= \ No newline at end of file +POSTGRES_DB=siren \ No newline at end of file diff --git a/.version b/.version index a571b01..6fcdfad 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -export SIREN_VERSION=0.2.0 \ No newline at end of file +SIREN_VERSION=0.2.1 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 123fed6..f90c761 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1372,7 +1372,7 @@ dependencies = [ [[package]] name = "siren" -version = "0.2.0" +version = "0.2.1" dependencies = [ "dotenv", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index e14b99a..0fd885c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,8 @@ [package] name = "siren" -version = "0.2.0" +version = "0.2.1" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] dotenv = "0.15.0" serde_json = "1.0" diff --git a/Dockerfile b/Dockerfile index 3c57b30..b96e029 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +9,12 @@ WORKDIR /packages RUN apt-get update && apt-get install -y curl tar xz-utils RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux > yt-dlp && \ chmod +x yt-dlp -RUN curl -L https://github.com/yt-dlp/FFmpeg-Builds/releases/latest/download/ffmpeg-master-latest-linux64-gpl.tar.xz > ffmpeg.tar.xz && \ +RUN curl -L https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz > ffmpeg.tar.xz && \ tar -xJf ffmpeg.tar.xz --wildcards */bin/ffmpeg --transform='s/^.*\///' && rm ffmpeg.tar.xz FROM debian:bullseye-slim as runtime WORKDIR /siren RUN apt-get update && apt-get install -y libopus-dev ffmpeg youtube-dl -COPY --from=builder /siren/target/release/siren siren +COPY --from=builder /siren/target/release/siren /usr/local/bin/siren COPY --from=packages /packages /usr/bin -CMD ["./siren"] +CMD ["siren"] diff --git a/Makefile b/Makefile index 9253c66..af44f7e 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,26 @@ +#!make SHELL := /bin/bash -include .version include .env +include .version +export $(shell sed 's/=.*//' .env) +export $(shell sed 's/=.*//' .version) + +.PHONY: help build test up down exec clean build: - # if docker inspect siren > /dev/null 2>&1; then docker rmi siren; fi; docker-compose build - docker build -t siren . + docker build -t siren:${SIREN_VERSION} . test: - # docker run --rm -it siren:latest bash - docker run --env-file .env -it --rm --name siren siren:latest + docker run --env-file .env -it --rm --name siren siren:${SIREN_VERSION} up: - if [[ ! $$(docker images -q siren 2> /dev/null) ]]; then docker-compose build; fi; \ - docker-compose up -d + docker compose up -d down: - docker-compose down + docker compose down exec: docker exec -it siren bash clean: docker rmi siren - -deploy: - @echo "Deploying application..." - @mvn clean deploy || { \ - echo "Deployment failed!"; \ - exit 1; \ - } - @echo "Deployment successful!" diff --git a/README.md b/README.md index 2414fea..c51bc87 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ https://discord.com/api/oauth2/authorize?client_id=&permissions=40671 - The CLIENT_ID can be found in the General Information tab on the Discord Developer Portal for your application, under `Application ID` 1. Copy `.env.TEMPLATE` to `.env` and fill out the fields -2. Start the application with `docker compose up -d` - - Requires [Docker](https://www.docker.com/) +2. Build the [Docker](https://www.docker.com/) application with `make build` +3. Start the application with `make up` ## Contributing [Rust](https://www.rust-lang.org/) must be installed to run locally. See [serenity-rs/serenity](https://github.com/serenity-rs/serenity) for more information about Rust Discord API Library. @@ -40,6 +40,6 @@ Begin the application with `cargo run` The application can also be tested from within a Docker container: ``` -docker build -t siren . +docker build -t siren:latest . docker run --env-file .env -it --rm --name siren siren:latest ``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9db9103..e86eb79 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,31 +2,30 @@ version: '3' services: siren: - image: siren + image: siren:${SIREN_VERSION} container_name: siren build: context: . dockerfile: ./Dockerfile args: - VERSION=${SIREN_VERSION} - volumes: - - ./app:/usr/src/siren + #volumes: + # - ./app:/siren environment: DISCORD_TOKEN: ${DISCORD_TOKEN} - DATABASE_URL: jdbc:postgresql://db:5432/${POSTGRES_DB} - DATABASE_USERNAME: ${POSTGRES_USER} - DATABASE_PASSWORD: ${POSTGRES_PASSWORD} + DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB} depends_on: - db restart: unless-stopped db: image: postgres:latest + container_name: siren_db environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} - volumes: - - ./data:/var/lib/postgresql/data + #volumes: + # - ./data:/var/lib/postgresql/data ports: - "5432:5432" - restart: unless-stopped \ No newline at end of file + restart: unless-stopped