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

Allow re-use of existing environment #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kzlar
Copy link
Contributor

@kzlar kzlar commented Jun 3, 2024

Hello,

Figured I'd take a stab at this issue.
Let me know if this looks good.

Thank you

@kzlar
Copy link
Contributor Author

kzlar commented Jun 14, 2024

Hi @Faolain , any thoughts on the above? Thanks!

@Faolain
Copy link
Owner

Faolain commented Aug 29, 2024

Hey @kzlar I responded on the issue itself but I'm curious what is the usecase behind using the destination environment if it already exists? Is this to continue deploying updates for a PR that has already been opened totally from a Github action side? (The reason I ask is that I have railway automatically handle all further updates beyond the initial PR open via the railway -> github integration where it watches the repo and autodeploys on subsequent prs, so in reality the environment creation should only be done once unless I'm misunderstanding)

@kzlar
Copy link
Contributor Author

kzlar commented Sep 4, 2024

Hi @Faolain thank you for your reply.
What I'm trying to do is build my app while directing it to the PR environment. So not only do I need to deploy (and re-deploy) on updates, but I need the Github Action to pass and set the PR environment domain as an output.
Perhaps issuing a manual redeploy is unnecessary, but I'd still need a way to run the action every time and output the domain.
Does that make things clearer?

@Faolain
Copy link
Owner

Faolain commented Sep 28, 2024

You're very welcome sorry for the delay. Hmm I don't think I understand, would you be able to describe your current workflow? I can describe how I use it, right now I use vercel, neon, and railway. I have to get the output of the environment to set it as my Vercel API endpoint, and at the same time take the neondb output and use that as an input for my PR environment on Railway. With the current setup ensuring that I have the Repo connected to Railway on the dashboard for github updates I use the following workflow:

jobs:
  deploy:
    runs-on: ubuntu-latest
    if: github.event_name != 'pull_request' || github.event.action != 'closed'
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.head_ref }} # Check out the source branch of the PR

      - name: Create a Neon Branch 🚀
        uses: neondatabase/create-branch-action@v4
        with:
          project_id: ${{ secrets.NEON_PROJECT_ID }}
          parent: staging
          branch_name: pr-${{ github.event.pull_request.number }}
          api_key: ${{ secrets.NEON_API_KEY }}
        id: create_branch

      - name: Create PR environment on Railway
        id: railway_deploy
        if: github.event.action == 'opened' || github.event.action == 'reopened'
        uses: Faolain/[email protected]
        with:
          RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
          PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
          SRC_ENVIRONMENT_NAME: staging
          DEST_ENV_NAME: pr-${{ github.event.pull_request.number }}
          PROVIDER: python
          ENV_VARS: '{"LOG_DD_AGENT_HOST": "", "APP_ENVIRONMENT": "docker", "DATABASE_URL": "postgresql+asyncpg://${{ secrets.NEON_USERNAME }}:${{ secrets.NEON_DB_PASSWORD }}@${{ steps.create_branch.outputs.host}}/neondb", "REDIS_URL": "redis://default:${{ steps.create_redis.outputs.redis_password }}@${{ steps.create_redis.outputs.redis_endpoint }}:${{ steps.create_redis.outputs.redis_port }}"}'
          branch_name: ${{ github.head_ref }}

As this action only deals with railway and doesn't affect neon (or any database for that matter). With the above setup it reuses the existing environment in that it creates the environment only once, from there on out the deployment trigger handles the update of the code itself so it doesn't need to redeploy over and over. The output of the first deploy should be fixed no? In my case I have it set to the PR name so pr-151.testapp-railway.? Does this make sense? Curious as to your setup.

@kzlar
Copy link
Contributor Author

kzlar commented Sep 30, 2024

Thank you for your reply @Faolain and I appreciate the example you posted.
What I have and is missing from your example is getting the URL of the newly created service:
So the job also has:

outputs:
      domain: ${{ steps.railway_deploy.outputs.service_domain }}

And the workflow has

outputs:
      domain:
        description: URL to the deployed service
        value: ${{ jobs.deploy.outputs.domain }}

On a branch new PR this works, but due to if: github.event.action == 'opened' || github.event.action == 'reopened' if I just update the PR with new commits, the output would be blank.

I realize that the domain doesn't change since it's the same PR, however my further downstream workflows rely on getting the domain - for example to run tests on the deployment or send an automated mail with the link.

Does this help explain the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants