Skip to content

Commit

Permalink
use docker-compose to install redis-stack image
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-nork committed Jul 12, 2023
1 parent 2b6d7e9 commit 26b4f27
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
52 changes: 18 additions & 34 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:0-3.11",
"features": {
"ghcr.io/devcontainers-contrib/features/rabbitmq-asdf:1": {
"version": "latest",
"erlangVersion": "latest"
},
"ghcr.io/devcontainers-contrib/features/redis-homebrew:1": {
"version": "latest"
},
"ghcr.io/devcontainers-contrib/features/vault-asdf:2": {
"version": "latest"
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
{
"name": "Python 3",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",
"features": {
"ghcr.io/devcontainers-contrib/features/rabbitmq-asdf:1": {
"version": "latest",
"erlangVersion": "latest"
},
"ghcr.io/devcontainers-contrib/features/vault-asdf:2": {
"version": "latest"
}
},
"postCreateCommand": "sudo curl -L 'https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)' -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose"
// "remoteUser": "vscode"
}
24 changes: 24 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.8'

services:
app:
image: mcr.microsoft.com/devcontainers/python:0-3.11
volumes:
- ..:/workspace:cached
command: sleep infinity
networks:
default:
aliases:
- localhost

redis:
image: redis/redis-stack:latest
ports:
- 6379:6379
networks:
default:
aliases:
- localhost

networks:
default:
17 changes: 9 additions & 8 deletions chirps/base_app/management/commands/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ def add_arguments(self, parser):
parser.add_argument('--stop', action='store_true', help='Stop redis server')
parser.add_argument('--status', action='store_true', help='Check redis server status')

def handle(self, *args, **options):
"""Handle redis command"""
if options['start']:
os.system('redis-server --daemonize yes')
elif options['stop']:
os.system('redis-cli shutdown')
elif options['status']:
os.system('redis-cli ping')
def handle(self, *args, **options):
"""Handle redis command"""
if options['start']:
os.system('docker-compose -f /workspace/.devcontainer/docker-compose.yml up -d redis')
elif options['stop']:
os.system('docker-compose -f /workspace/.devcontainer/docker-compose.yml down')
elif options['status']:
os.system('docker-compose -f /workspace/.devcontainer/docker-compose.yml ps')

0 comments on commit 26b4f27

Please sign in to comment.