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

Add workflow for docker build and push #750

Merged
merged 4 commits into from
Jun 26, 2023

Conversation

Adito5393
Copy link
Contributor

@Adito5393 Adito5393 commented Mar 27, 2023

Summary

This PR adds automation to build and deploy the Docker image to Docker Hub through two triggers:

  • Every push to the main branch
  • Every tag with the format v*.*.* (see https://semver.org/ for more information)

If you prefer to deploy only on tags and not on every branch push, you can remove lines 5 and 6:

branches:
  - main

Additionally, two secret variables are required in the GitHub settings:

  • DOCKERHUB_USERNAME
  • DOCKERHUB_TOKEN

The token can be generated from https://hub.docker.com/settings/security.

Please merge this PR to enjoy the automation.

Testing

I tested this PR by forking the repo and deploying it at https://hub.docker.com/r/adito5393/mediacms/tags.
The development was done on the add-dockerhub-release-with-all-tags branch.
The GitHub Actions output can be viewed at https://github.com/Adito5393/mediacms/actions/workflows/docker-build-push.yml.

@Adito5393
Copy link
Contributor Author

Hey @mgogoulos

I have organized the CI jobs to ensure that the software does not get released if it fails the unit tests or linting. For more details, see:

Here you can see the CI output of a project with similar workflow dependency layout.

@mgogoulos
Copy link
Contributor

Awesome work @Adito5393 , I will review it during this week. Thanks a lot

@Adito5393
Copy link
Contributor Author

Hey @mgogoulos,
Congrats on the new v2.0.0 release!

What is holding this PR to be merged? Is there anything I can help with?
Such that we can rely on the official docker images for rolling back versions! (especially now with a major release, would have been awesome to have it already merged)

At the moment, the only DockerHub tag available is the latest 😔

@mgogoulos
Copy link
Contributor

Hi, it has just been a matter of not having enough capacity to test it. But your instructions are very good, so I am now merging it after having created the two secret variables

@mgogoulos mgogoulos merged commit 367faad into mediacms-io:main Jun 26, 2023
@mgogoulos
Copy link
Contributor

Merged, thanks for this! It might require some calibration, as it happens in similar cases where some new workflow is introduced, let's find out!

@mgogoulos
Copy link
Contributor

@Adito5393 please let me know if you want to help in other issues too. There are devops/infrastructure/dev experience related tickets, as upgrade of all libraries and software, improve the Docker Compose files, provide a clear path for Developmnent etc so it would be great to help there too, or on other issues that interest you more!

@Adito5393 Adito5393 deleted the docker-build-release-ci branch June 26, 2023 07:34
@Adito5393
Copy link
Contributor Author

Hey, thanks! I will be available for support for whatever calibration is required.
I'll have a look at the issue tracker, but meanwhile, PR #749 is ready for review! You can remove the minor version and pin only the major version of the DB. (because now 15.3 is the latest released)
The addition of the TZ variable is based on the tzdata package being available.

@Adito5393
Copy link
Contributor Author

By the way, I just noticed that you have Automated Builds setup via DockerHub UI(?!):
image

I recommend disabling it because you only want to build the docker image if your commits/changes pass the tests. This is handled by the new GitHub Action workflow.

@mgogoulos
Copy link
Contributor

I've disabled it, it was part of DockerHub

@mgogoulos
Copy link
Contributor

Hi @Adito5393 , I have created a test PR and it fails to complete, see

https://github.com/mediacms-io/mediacms/actions/runs/5388845143/jobs/9782101845?pr=823

I've added these two secrets on the settings.

Screenshot from 2023-06-27 13-51-44

Do you have any clues what is happening?

Also not sure I understand what this will do, will it push an image to Docker Hub in this case? (this is a PR, it's not merged with master yet)

Thanks

@Adito5393
Copy link
Contributor Author

It fails because the secrets are probably disabled in PR. We can modify the job release to be skipped if it is a PR.
The following part from ci.yml should be:

  release:
    uses: ./.github/workflows/docker-build-push.yml
    needs: [test]
    if: github.event_name != 'pull_request'

I will test it on my fork this evening and let you know if it works.

You might also want to skip CI for all files inside the docs directory, via paths-ignore:

    paths-ignore:
      - '**/README.md'
      - 'docs/**'

@mgogoulos
Copy link
Contributor

This works, and i also changed on ci.yml to use main instead of master.

However, it is still unable to read the repository secrets, and this is very weird :(

@Adito5393
Copy link
Contributor Author

Adito5393 commented Jun 27, 2023

Hm, it was a syntax error... I guess your last commit fixed it a1962d4
You can add the username as a env variable and use [ci skip]

EDIT: I was to fast to reply :)
Can you verify that you can log in using the same token that you added on Github?
docker login --username <username>
Does the token have the correct access permissions? To read and write, but not to delete, for example.

@Adito5393
Copy link
Contributor Author

You can see here, how my fork has the secrets config and they work just fine:
image

@Adito5393
Copy link
Contributor Author

Adito5393 commented Jun 27, 2023

@mgogoulos, The debug logs clearly show that the secrets are not set:

##[debug]Evaluating: secrets.DOCKERHUB_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'DOCKERHUB_TOKEN'
##[debug]=> null
##[debug]Result: null
##[debug]Loading env

Could you remove it and try a new token? (force reset it)

@mgogoulos
Copy link
Contributor

I'm pausing for now but will try out tomorrow again. I did remove it and then added it a couple of times, and I even added it as an organization secret, but on all cases it shows as null on the debug logs. Something strange happening here!

@mgogoulos
Copy link
Contributor

1fd04ca
that fixed it, the secrets needed to be inhereted, since this is using a workflow (and not a straight yml file)

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