Skip to content

Commit

Permalink
finish up
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbloch committed Nov 6, 2020
1 parent 18800f8 commit 3515ad0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM clojure:openjdk-14-lein-2.9.1-slim-buster
FROM clojure:openjdk-11-lein-2.9.1-slim-buster

# Update the system and install netstat command
RUN apt-get update
RUN apt-get install net-tools
RUN apt-get install -y net-tools
RUN apt-get install -y netcat

# download the dependencies and compile the project ahead of time. This will significantly reduce startup time when you run your image
RUN mkdir -p /g2
Expand All @@ -18,9 +19,9 @@ COPY dev-config_template.edn /g2/dev-config.edn

RUN lein uberjar

EXPOSE 3000
# Copy stuff that is not needed for compilation
COPY scripts /g2/scripts

COPY scripts/add-docker-host-to-hosts-file.sh /g2/add-docker-host-to-hosts-file.sh
RUN chmod +x add-docker-host-to-hosts-file.sh
EXPOSE 3000

COPY *entrypoint.sh /g2/
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
docker-local:
sudo docker-compose -f local.docker-compose.yml down -v && \
sudo docker-compose -f local.docker-compose.yml up -d

docker-app-logs:
sudo docker-compose -f local.docker-compose.yml exec backend tail -f log/g2.log
docker-shell:
sudo docker-compose -f local.docker-compose.yml exec backend bash


docker-staging:
sudo docker build -t g2-backend-img . && \
sudo docker run -d -p "3333:3000" \
Expand All @@ -11,3 +19,4 @@ docker-staging:
run-jar-with-dev:
java -Dconf=dev-config.edn -jar target/uberjar/g2.jar migrate && \
java -Dconf=dev-config.edn -jar target/uberjar/g2.jar

9 changes: 5 additions & 4 deletions local.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: "3"
version: '3.7'

services:
backend:
container_name: g2-backend_server
Expand All @@ -12,11 +13,12 @@ services:
ports:
- "3000:3000"
environment:
DATABASE_URL: mysql://db:3306/g2_dev?user=g2_user&password=local-pass&serverTimezone=UTC
DATABASE_URL: "mysql://db:3306/g2_dev?user=g2_user&password=local-pass&serverTimezone=UTC"
GITHUB_PERSONAL_ACCESS_TOKEN: "af2aa061c70d1c029b1f5001c806392b4ddcf4ab"
entrypoint: [ "sh", "stag-entrypoint.sh" ]
db:
container_name: g2-backend_db
image: mariadb:latest
image: mariadb:10.5-focal
volumes:
- database:/var/lib/mysql
networks:
Expand All @@ -26,7 +28,6 @@ services:
MYSQL_DATABASE: g2_dev
MYSQL_USER: g2_user
MYSQL_PASSWORD: local-pass
restart: always

networks:
base:
Expand Down
9 changes: 5 additions & 4 deletions resources/migrations/20191127155136-setup-db.down.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ drop table if exists named_tags cascade;
--;;
drop table if exists projects cascade;
--;;
Drop table if exists named_tags cascade;
drop table if exists repo_default_tag_mapping cascade;
--;;
drop table if exists repository_labels cascade;
--;;
drop table if exists repos cascade;
--;;
drop table if exists repository_providers cascade;
--;;
drop table if exists schema_migrations cascade;
--;;
drop table if exists tag_relations cascade;
--;;
drop table if exists tags cascade;
--;;
drop table if exists zeus_users cascade;
--;;
drop table if exists users cascade;
--;;
drop table if exists tags cascade;
--;;
12 changes: 12 additions & 0 deletions scripts/wait_for_service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if [ $# -ne 2 ]; then
echo "Usage: $0 <hostname> <port>" >&2
exit 1
fi

while ! nc -z "$1" "$2"; do
echo "$1:$2 not yet available, waiting"
sleep 1
done
echo "Done"
2 changes: 1 addition & 1 deletion src/clj/g2/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
;; coercing response bodies
coercion/coerce-response-middleware
;; exception handling
exception/exception-middleware
#_exception/exception-middleware
]}
#_["/" {:get {:handler (constantly {:status 301 :headers {"Location" "/api-docs/index.html"}})}}]
(app-routes)]
Expand Down
13 changes: 10 additions & 3 deletions stag-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/sh

# Add docker host address to the hosts file
./add-docker-host-to-hosts-file.sh
./scripts/add-docker-host-to-hosts-file.sh

./scripts/wait_for_service db 3306

echo "Migration with the following database"
echo "$DATABASE_URL"

# migrate and run the application
java -Dconf=dev-config.edn -jar target/uberjar/g2.jar migrate && \
java -Dconf=dev-config.edn -jar target/uberjar/g2.jar migrate || exit 1
echo "Migration done."
echo "Starting server"
java -Dconf=dev-config.edn -jar target/uberjar/g2.jar

0 comments on commit 3515ad0

Please sign in to comment.