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

feat: add workflow that builds Docker and push to ECR without using artifacts #11

Closed
wants to merge 22 commits into from

Conversation

sgametrio
Copy link
Contributor

@sgametrio sgametrio commented Jan 4, 2024

It's faster

@sgametrio sgametrio changed the title feat: add workflow feat: add workflow that builds Docker and push to ECR without using artifacts Jan 5, 2024
Copy link
Contributor

@swibrow swibrow left a comment

Choose a reason for hiding this comment

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

Looks good

I would make push an input and make it default true.

  docker_push:
    description: "Push Image to ECR"
    type: boolean
    required: false
    default: true

push: true
tags: |
${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.REGISTRY }}/${{ env.REPOSITORY }}:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a condition here to be master or main or feature branches will push to latest.
Also add the git sha, should always be a tag on an image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@swibrow I agree with this. I was running into errors though if I was specifying twice the SHA (because IMAGE_TAG was also assuming the git.sha value). That's why I removed it. Should I make a condition? but then not sure how to parametrize the tags parameter dynamically of the custom action...

Copy link
Contributor

Choose a reason for hiding this comment

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

tags: |
${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ github.sha }}
${{ env.IMAGE_TAG != github.sha && format('{0}/{1}:{2}', env.REGISTRY, env.REPOSITORY, env.IMAGE_TAG) }}

something like that (not tested) or just use standard docker commands since running the same tag command wont error.

Also if you want to use the docker action, theres also a tag extractor
https://docs.docker.com/build/ci/github-actions/manage-tags-labels/

@@ -173,6 +172,11 @@ jobs:
run: |
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY

# Added this step because otherwise the UI shows a green checkmark
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be added to the step above?

I would remove the comment

Copy link
Contributor Author

@sgametrio sgametrio Jan 10, 2024

Choose a reason for hiding this comment

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

@swibrow

  1. We want to create anyway the summary, so we can't exit before that.
  2. We don't want to exit at the summary step or this would be misleading because it would look like the summary step failed while it was the plan one that failed.

What do you think? I think like this is the cleanest I could think of.

push: true
tags: |
${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.REGISTRY }}/${{ env.REPOSITORY }}:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

tags: |
${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ github.sha }}
${{ env.IMAGE_TAG != github.sha && format('{0}/{1}:{2}', env.REGISTRY, env.REPOSITORY, env.IMAGE_TAG) }}

something like that (not tested) or just use standard docker commands since running the same tag command wont error.

Also if you want to use the docker action, theres also a tag extractor
https://docs.docker.com/build/ci/github-actions/manage-tags-labels/

@@ -173,8 +181,12 @@ jobs:
run: |
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY

- name: Exit if `terraform plan` failed
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed anymore. since it wont make it this far

exit 1
else
exit 0
fi
continue-on-error: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah this should be removed I guess

- name: Terraform Apply
if: (github.ref_name == github.event.repository.default_branch && github.event_name == 'push' && steps.plan.outputs.exitcode == '2') || inputs.tf_deploy_override == true
Copy link
Contributor

Choose a reason for hiding this comment

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

You want this actually since you only want to run an apply when theres changes.

@sgametrio sgametrio closed this Jan 11, 2024
@rbapst-tamedia rbapst-tamedia deleted the include-build-and-push-no-artifacts branch January 10, 2025 11:59
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