Skip to content

Instantly share code, notes, and snippets.

@zodman
Last active July 10, 2022 03:48
Show Gist options
  • Save zodman/9c32a034e6dc49e9426b70252e75afa2 to your computer and use it in GitHub Desktop.
Save zodman/9c32a034e6dc49e9426b70252e75afa2 to your computer and use it in GitHub Desktop.
Dokku clamav running with scan virus as a service with api rest
##
# this script born about the needs of implement a virus scanner for files using a api rest.
# then using https://github.com/benzino77/clamav-rest-api/ and https://dokkupose.netlify.app
# I create this script to deploy the api rest
##
### dokku apps:destroy clamav-service && dokku apps:destroy clamav-apirest && dokku network:destroy clamav-net
# Let's create a network bridge to communicate
dokku apps:create clamav-service
dokku apps:create clamav-restapi
# network configuration
dokku network:create clamav-net
# attach the network to the cointainers
dokku network:set clamav-service attach-post-create clamav-net
dokku network:set clamav-restapi attach-post-create lamav-net
# doing this i have acces from clamav-restapi to clamav-service throught clamav-service.web
# for not expose the ports through nginx
dokku config:set --no-restart clamav-service DOKKU_DISABLE_PROXY=1
dokku git:from-image clamav-service clamav/clamav:0.104
# check if get working
sleep 5
nc -vz $(dokku network:report clamav-service --network-web-listeners | tr ':' ' ')
# then it is working now install the restapi
# clamav-restapi
dokku apps:create clamav-restapi
# configure ports of clamav-restapi
dokku config:set --no-restart clamav-restapi DOKKU_DOCKERFILE_PORTS="3000/tcp"
dokku config:set --no-restart clamav-restapi DOKKU_PROXY_PORT_MAP="http:80:3000"
dokku config:set --no-restart clamav-restapi DOKKU_LETSENCRYPT_EMAIL="[email protected]"
dokku config:set --no-restart clamav-restapi NODE_ENV="production"
# using the network reference
dokku config:set --no-restart clamav-restapi CLAMD_IP=clamav-service.web
dokku config:set --no-restart clamav-restapi APP_FORM_KEY="FILES"
dokku config:set --no-restart clamav-restapi APP_PORT="3000"
#show the env vars
dokku config:show clamav-restapi
# assign image to clamav-restapi
dokku git:from-image clamav-restapi benzino77/clamav-rest-api
# configure ssl for the domain
dokku letsencrypt:enable clamav-restapi
# lets rock!
curl -s $(dokku url clamav-restapi)/api/v1/version | python3 -m json.tool
# secure the application
dokku plugin:install https://github.com/dokku/dokku-http-auth.git
export RANDOM_PASSWORD=$(date | md5sum | awk '{print $1}')
dokku http-auth:enable clamav-restapi app $RANDOM_PASSWORD
curl -s -u app:$RANDOM_PASSWORD $(dokku url clamav-restapi)/api/v1/version | python3 -m json.tool
{
"success": true,
"data": {
"version": "ClamAV 0.104.3/26595/Wed Jul 6 07:53:23 2022\n"
}
}
echo "your password is $RANDOM_PASSWORD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment