Skip to content

Commit

Permalink
Add env vars to k8s driver deployments. Enable pushing images from CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Feb 15, 2023
1 parent 0ba3830 commit d95e654
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/universal-resolver-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ jobs:
env:
DOCKER_FILE: uni-resolver-web/docker/Dockerfile
CONTAINER_TAG: identitydotcom/uni-resolver-web:latest
DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD : ${{ secrets.DOCKER_PASSWORD }}
1 change: 1 addition & 0 deletions ci/deploy-k8s-aws/scripts/k8s-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ spec:
capabilities:
drop:
- NET_RAW
{{environmentVariables}}
{{configMapVolume}}

---
Expand Down
41 changes: 41 additions & 0 deletions ci/deploy-k8s-aws/scripts/prepare-deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def generate_deployment_specs(containers, outputdir):
for container in containers:
container_tag = containers[container]['image']
container_port = get_container_port(containers[container]['ports'])
container_env = containers[container]['environment'] if 'environment' in containers[container] else None
fin = open("k8s-template.yaml", "rt")
deployment_file = "deployment-%s.yaml" % container
fout = open(outputdir + '/' + deployment_file, "wt")
Expand All @@ -55,10 +56,50 @@ def generate_deployment_specs(containers, outputdir):

fin.close()
fout.close()

add_driver_environment_variables(outputdir, container_env, container)

# If there is a configmap-<driver>.yaml file, create a ConfigMap for it and add a volumeMounts mapping for it:
add_driver_configmap_volume(outputdir, container)
add_deployment(deployment_file, outputdir)

def add_driver_environment_variables(outputdir, container_env, container):
"""
If the container has environment variables defined in the docker-compose file,
add them here.
NOTE: This does not support variable substitution
"""

deployment_file = "deployment-%s.yaml" % container
with open(outputdir + '/' + deployment_file, 'r') as infile:
input_deployment_contents = infile.read()

configmap_filename = 'configmap-%s.yaml' % container
configmap_path = '/app-specs/%s' % configmap_filename

if container_env is None:
print('No environment variables found for driver ' + container)
output_deployment_contents = input_deployment_contents.replace('{{environmentVariables}}', '')
else:
print('Environment variables found for driver ' + container + ' . Adding environment to the deployment yaml.')

# Write the environment definition to the driver Deployment spec:
env_txt = 'env:\n'

for env_var in container_env:
env_txt += ' - name: %s\n' % env_var
env_txt += ' value: %s\n' % container_env[env_var]

print(env_txt)

output_deployment_contents = input_deployment_contents.replace('{{environmentVariables}}', env_txt)

# tmp
print(output_deployment_contents)

with open(outputdir + '/' + deployment_file, 'w') as outfile:
outfile.write(output_deployment_contents)

def add_driver_configmap_volume(outputdir, container):
"""
If there is a file named /app-specs/configmap-<container>.yaml for this driver,
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-build-push/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fi

if [ -z "${DOCKER_FILE}" ]
then
echo "No Dockerfile spectified. Using default file: Dockerfile"
echo "No Dockerfile specified. Using default file: Dockerfile"
DOCKER_FILE=Dockerfile
fi

Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3.5"

### NOTE - this file is used to generatee the Kubernetes pods
### NOTE - this file is used to generate the Kubernetes pods
# Enable any DID drivers we want to support.
# If enabling drivers, check if special config needs to be uncommented in ci/scripts/driver-config.yaml
# or entrypoint.sh (e.g. bitcr)
Expand Down Expand Up @@ -85,10 +85,10 @@ services:
# image: sphereon/driver-did-factom:latest
# ports:
# - "8097:8080"
driver-did-key:
image: universalresolver/driver-did-key:latest
ports:
- "8098:8080"
# driver-did-key:
# image: universalresolver/driver-did-key:latest
# ports:
# - "8098:8080"
# dock-did-driver:
# image: docknetwork/dock-did-driver:latest
# ports:
Expand Down Expand Up @@ -200,8 +200,8 @@ services:
driver-didkit:
image: ghcr.io/spruceid/didkit-http:latest
environment:
PORT: 8080
HOST: 0.0.0.0
PORT: "8080"
HOST: "0.0.0.0"
ports:
- "8121:8080"
# eosio-driver:
Expand Down

0 comments on commit d95e654

Please sign in to comment.