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

Build another docker image that uses the .env.staging file instead of .env.production and tag it with "staging" #36

Merged
merged 10 commits into from
Aug 30, 2024

Conversation

NicoBiernat
Copy link
Member

This is definitely a hacky little solution but it might work for simply building a second docker image with the .env.development file instead of the default .env.production file that is used when building the website.

How it "works" (we'll see if it works, when the action runs successfully):
In GitHub Actions I added a copy of the metadata and build-and-push action steps where an environment variable with the value "dev" is passed as a docker build-arg to the Dockerfile. The Dockerfile then appends this environment variable to npm run build which then becomes npm run builddev which conveniently is a script in package.json that uses the env-cmd tool to run craco build with the .env.development file.

@NicoBiernat NicoBiernat requested a review from fwcd August 28, 2024 23:10
@NicoBiernat NicoBiernat self-assigned this Aug 28, 2024
Dockerfile Outdated Show resolved Hide resolved
Comment on lines 41 to 49
- id: meta-dev
uses: docker/metadata-action@v5
with:
images: ghcr.io/projectlighthousecau/luna
tags: |
type=raw,value=dev,enable={{is_default_branch}}
type=sha,format=long
- name: Build and Push dev image
uses: docker/build-push-action@v5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of running these sequentially, I'd suggest running them either as parallel jobs, maybe via different matrix configurations. This would avoid a fair bit of duplication here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that there might be a way to avoid code duplication, but I didn't know how, so I simply duplicated it.
Feel free to refactor 😄

.github/workflows/docker.yml Outdated Show resolved Hide resolved
@NicoBiernat
Copy link
Member Author

Docker build takes too long, I cancelled it after 6 minutes. On my laptop it took ~24 minutes.
@fwcd Do you know what change might cause it to take this long?

@fwcd
Copy link
Member

fwcd commented Aug 28, 2024

Docker CI on the main branch takes 2 minutes: https://github.com/ProjectLighthouseCAU/luna/actions/runs/10551448727/job/29228906391

So it really shouldn't take that long. Not sure why that happens for you locally, in CI my only guess would be that the aarch64 build is slow under emulation, but with the --platform=$BUILDPLATFORM flag that shouldn't be needed.

@NicoBiernat
Copy link
Member Author

That must have been the problem, now the CI runs fast enough (could be sped up with parallel execution though).
And the "Build and push dev image" step successfully executed env-cmd -f .env.development craco build instead of craco build.

@fwcd fwcd changed the title Build another docker image that uses the .env.development file instead of .env.production and tag it with "dev" Build another docker image that uses the .env.staging file instead of .env.production and tag it with "staging" Aug 30, 2024
@fwcd fwcd merged commit 0664d6d into main Aug 30, 2024
3 checks passed
@fwcd fwcd deleted the docker-image-dev-env branch August 30, 2024 15:28
@fwcd
Copy link
Member

fwcd commented Aug 30, 2024

Thanks!

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