Skip to content

Commit

Permalink
docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Khasanov committed Dec 18, 2021
1 parent cdc1c29 commit dc5578f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
5 changes: 4 additions & 1 deletion devenv/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
COMPOSE_PROJECT_NAME=go-sandbox

# порт Go-сервера, который будет открыт на хост-машине
GO_EXPOSE_PORT=8080
GO_EXPOSE_PORT=8080

# Postgres
POSTGRES_EXPOSE_PORT=5432
33 changes: 30 additions & 3 deletions devenv/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
version: "3"

volumes:
postgres_data:
driver: local
redis_data:
driver: local

services:
go-docker-image:
go:
container_name: ${COMPOSE_PROJECT_NAME}-go
build:
context: ../
dockerfile: docker/go/Dockerfile
dockerfile: devenv/go/Dockerfile
ports:
- '${GO_EXPOSE_PORT}:80'
- "${GO_EXPOSE_PORT}:80"
volumes:
- "../:/app"
networks:
- selfteam-components-net

postgres:
container_name: ${COMPOSE_PROJECT_NAME}-postgres
build:
context: ./
dockerfile: postgres/Dockerfile.postgres
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- DATABASE_NAME=${COMPOSE_PROJECT_NAME}
ports:
- "${POSTGRES_EXPOSE_PORT}:5432"
volumes:
- "postgres_data:/var/lib/postgresql/data"
- "./postgres/init.d/:/docker-entrypoint-initdb.d/"
networks:
- selfteam-components-net

networks:
selfteam-components-net:
Expand Down
1 change: 1 addition & 0 deletions docker/go/Dockerfile → devenv/go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM golang:latest

WORKDIR /app
COPY ./ /app

RUN go mod download
RUN go get github.com/githubnemo/CompileDaemon

Expand Down
1 change: 1 addition & 0 deletions devenv/postgres/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
3 changes: 3 additions & 0 deletions devenv/postgres/Dockerfile.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres:13-alpine

RUN mkdir -p "$PGDATA" && chmod 700 "$PGDATA"
21 changes: 21 additions & 0 deletions devenv/postgres/init.d/init-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e

# Создать пользователя
# Установить пароль
# Назначить роль Суперпользователя
# Для созданной БД активировать расширение для генерации GUID сресдтвами БД

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER docker;
ALTER USER docker WITH PASSWORD '4757';
ALTER USER docker WITH SUPERUSER;
CREATE DATABASE $DATABASE_NAME;
GRANT ALL PRIVILEGES ON DATABASE $DATABASE_NAME TO docker;
\connect $DATABASE_NAME;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
EOSQL

0 comments on commit dc5578f

Please sign in to comment.