Question

I cannot get App-Level Env Vars to be passed to my spring boot app

Hi,

I am struggling to use app-vars :)

Here is my list of env vars:

REGION = ams3
BRANCH_NAME = dev
ACTIVE_PROFILE = dev
DO_SPACES_SECRET = MY_SPACES_SECRETS
DO_DB_PASSWORD = MY_DB_PASSWORD

Here is my config and properties files:

app.yaml:

name: project_1-admin
region: REGION
services:
  - dockerfile_path: Dockerfile
    github:
      branch: BRANCH_NAME
      deploy_on_push: true
      repo: project_1/project_1
    name: web

Dockerfile:

FROM gradle:7.5-jdk17-alpine AS _build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
ARG ACTIVE_PROFILE
ARG DO_SPACES_SECRET
ARG DO_DB_PASSWORD
RUN gradle web:build --no-daemon --debug

FROM openjdk:17-jdk-slim
EXPOSE 8080
RUN mkdir /project_1
COPY --from=_build_ /home/gradle/src/web/build/libs/web*SNAPSHOT.jar /project_1/web.jar
ARG ACTIVE_PROFILE
ARG DO_SPACES_SECRET
ARG DO_DB_PASSWORD
ENTRYPOINT ["java", "-jar", "/project_1/web.jar"]

application.properties:

spring.profiles.active=${ACTIVE_PROFILE}

application-dev.properties:

digital.ocean.spaces.secret=${DO_SPACES_SECRET}
spring.datasource.password=${DO_DB_PASSWORD}

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
March 27, 2023

Hi there,

Have you tried to also define the environment variables in your deployment YAML file? For example:

name: project_1-admin
region: ams3
services:
  - dockerfile_path: Dockerfile
    github:
      branch: dev
      deploy_on_push: true
      repo: project_1/project_1
    name: web
    envs:
      - key: REGION
        value: ams3
      - key: BRANCH_NAME
        value: dev
      - key: ACTIVE_PROFILE
        value: dev
      - key: DO_SPACES_SECRET
        value: MY_SPACES_SECRETS
      - key: DO_DB_PASSWORD
        value: MY_DB_PASSWORD

For any sensitive env variables, you can se the scope to secret, eg:

# ...
services:
  - dockerfile_path: Dockerfile
    # ...
    envs:
      # ...
      - key: DO_SPACES_SECRET
        scope: SECRET
        value: my_do_spaces_secret
      - key: DO_DB_PASSWORD
        scope: SECRET
        value: my_do_db_password

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel