Giter Site home page Giter Site logo

szepeviktor / ci-cd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mathiasreker/java-ci-cd

0.0 1.0 0.0 136 KB

This is an example of building a CI/CD pipeline using GitHub actions. :white_check_mark::octocat::whale2:

License: MIT License

Shell 24.39% Java 72.21% Dockerfile 3.40%

ci-cd's Introduction

Contributors Forks Stargazers Issues MIT License CI/CD

CI/CD GitHub Action ๐Ÿš€

A CI/CD workflow for your maven project!

Getting Started

This is an example of building a CI & CD pipeline using GitHub actions.

The CI pipeline depends on maven to compile and test the project's code. JPA/MySQL is supported.

The CD pipeline will create a docker image of the project's code and deploy the image as a docker container along with a MySQL container on a remote server using SSH. The bridge driver of docker networks connects these containers.

In the docker-compose.yml, you can configure the tag of the images. By default, the tag of the project is dev. However, you can change the tag to a specific version to control the deployment. The workflow supports tags in the sem-version format like v*.*.*.

To create a new release using a specific tag, navigate to your GitHub repository. Go to tags -> create new release -> publish the release.

Prepare the production server

  1. Connect to your server

    ssh -i <private key path> <user>@<host>
  2. Add environment variables

    echo "MYSQL_ROOT_PASSWORD=myrootpw
    MYSQL_DATABASE=mydb
    MYSQL_USER=myuser
    MYSQL_PASSWORD=mypw
    DOCKER_IMAGE_NAME=ci-cd
    GITHUB_USER=mathiasreker" > ~/.env

    MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER and MYSQL_PASSWORD can be anything.

    DOCKER_IMAGE_NAME must match the name of the docker image defined in workflow.

    GITHUB_USER must be the user/organisation of the repository in lower case.

This script replaces step 3-7 (optional)

bash <(curl -s https://raw.githubusercontent.com/MathiasReker/CI-CD/develop/install.bash)
  1. Update and upgrade packages

    sudo apt-get update && sudo apt-get -y upgrade
  2. Install docker-compose

    sudo apt-get install -y docker-compose
  3. Generate a new key named github-actions with an empty password

    ssh-keygen -t rsa -b 4096 -f ~/.ssh/github-actions -q -P ""
  4. Copy the content of github-actions into authorized_keys

    cat ~/.ssh/github-actions.pub >> ~/.ssh/authorized_keys
  5. Grap the private key, as you will need it soon

    cat ~/.ssh/github-actions

Install action secrets

Navigate to your GitHub repository. Go to settings -> secrets -> actions.

Add the following secrets:

  • SSH_USER
  • SSH_HOST
  • SSH_PRIVATE_KEY

Install the workflow to your project

  1. Copy the workflow to this path of your repository: /.github/workflows/ci-cd.yml.

  2. Copy the docker-compose.yml to the root folder of your project.

  3. Copy the Dockerfile to the root folder of your project.

Depending on your project, it is necessary to adapt the docker-compose.yml and the Dockerfile.

Package visibility

To see the package, the CD pipeline must run at least once. The pipeline will create a package linked to your GitHub repository.

Navigate to your GitHub repository. Go to the package -> select package settings -> select danger zone -> change visibility -> make it public.

(back to top)

Usage

The CI pipeline is triggered on any change to the code on your repository.

The CD pipeline is triggered on push events. The CD pipeline will be skipped if the CI pipeline fails.

(back to top)

Roadmap

  • CI workflow
  • CD workflow
  • Unit test
  • Integration test using JPA

See the open issues for a complete list of proposed features (and known issues).

(back to top)

Contributing

If you have a suggestion to improve this, please fork the repo and create a pull request. You can also open an issue with the tag "enhancement". Finally, don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

It is distributed under the MIT License. See LICENSE for more information.

(back to top)

ci-cd's People

Contributors

dependabot[bot] avatar mathiasreker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.