Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically generate .env in Github Action workflow during the deployment. #20

Open
jiin-kim109 opened this issue Oct 12, 2023 · 0 comments
Assignees

Comments

@jiin-kim109
Copy link
Member

jiin-kim109 commented Oct 12, 2023

Description:
Our .env file contains important credentials used for Firebase access and potentially other backend services. However, including the .env file in the remote repository is not advisable, as anonymous readers could access secure credentials, posing a potential security threat.

Developers typically obtain the .env file and its credentials from the project lead. The application requires the .env file during its initialization stage to connect with services like Firebase. This means, however, the GitHub Action will fail because it lacks the .env file in its remote environment, unlike individual developers who have it in their local setup.

To learn more about GitHub Actions and CI/CD, visit:
https://www.youtube.com/watch?v=URmeTqglS58
https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

One solution to this issue is dynamically creating the .env file during the deployment. This way, when a node server boots up, it can operate with a generated .env file. GitHub supports a secret management feature called GitHub Secrets. To view the secrets in GitHub Secrets in our repository, navigate to the 'Settings' tab. On the left-hand side of the menu, you'll be able to find the 'Secrets' or 'Actions'.

The GitHub workflow can fetch the values of GitHub Secrets while it's running. Check out the following article to see how it works:
https://github.com/Azure/actions-workflow-samples/blob/master/assets/create-secrets-for-GitHub-workflows.md

Your task is straightforward. Since we have the .env.example file in the repository containing the names of the secret keys, you need to edit the .github/workflows/node.js.yml file and populate the values in GitHub Secrets corresponding to the keys in the .env.example file. After that, rename .env.example to .env before initiating the server app.

Below is an example code snippet you can refer to for editing the workflow:

- name: Create and populate .Renviron file
        env:
          AWS_HOST: ${{ secrets.AWS_HOST }}
          AWS_PORT: ${{ secrets.AWS_PORT }}
          AWS_PW: ${{ secrets.AWS_PW }}
          AWS_USER: ${{ secrets.AWS_USER }}
          DBNAME: ${{ secrets.DBNAME }}
        run: |
          touch .Renviron
          echo aws_host="$AWS_HOST" >> .Renviron
          echo aws_port="$AWS_PORT" >> .Renviron
          echo aws_pw="$AWS_PW" >> .Renviron
          echo aws_user="$AWS_USER" >> .Renviron
          echo dbname="$DBNAME" >> .Renviron

Acceptance Critieria:

  • modify .github/worfklows/node.js.yml to create .env file during the deployment. Scretes are provided in the Github Scretes. Find the matching keys in .env.example file, fill the values, and rename it.

  • Our Github Action is currently failing due to the missing env file during the workflow. The issue should be resolved if this ticket is completed correctly. You may make a multiple push to test Github Action runs.

@jiin-kim109 jiin-kim109 changed the title Generate .env in Github Action workflow during the deployment. Dynamically generate .env in Github Action workflow during the deployment. Nov 19, 2023
@Pentaminum Pentaminum self-assigned this Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

3 participants
@Pentaminum @jiin-kim109 and others