Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker Image deployments to Dockerhub and GitHub Container Registry with GitHub Actions

Docker Image deployments to Dockerhub and GitHub Container Registry with GitHub Actions

I gave a talk in German about:
Docker Image deployments to Dockerhub and GitHub Container Registry with GitHub Actions including a live demo with open source code you can also use.

Lothar Schulz

February 10, 2021
Tweet

More Decks by Lothar Schulz

Other Decks in Technology

Transcript

  1. Dockerhub &
    GitHub Container
    Registry Deployments
    mit GitHub Actions

    View Slide

  2. Me
    Engineering Manager
    lotharschulz.info
    github.com/lotharschulz
    @lothar_schulz
    lnkd.in/lotharschulz

    View Slide

  3. Einfacher Zugang zur täglichen Mobilität
    Mobimeo entwickelt die Plattform, die öffentliche
    Nahverkehrs- und Sharing-Angebote vernetzt -
    modular, flexibel zu integrieren und einfach zu
    nutzen.
    Dabei berücksichtigen wir die jeweilige Situation
    und Präferenz des Einzelnen. Unterwegs sein wird
    individueller, intuitiver und entspannter.
    Für mehr Mobilität bei weniger Verkehr.
    Mobimeo –
    Wir ändern wie sich Menschen in Städten bewegen

    View Slide

  4. View Slide

  5. View Slide

  6. https://github.blog/2019-08-08-github-actions-now-supports-ci-cd/
    What are GitHub Actions?
    Mit GitHub Actions sind Workflows und Schritte Code in einem Git Repository,
    sodass alle Vorteile von verteiltem Code genutzt werden können.

    View Slide

  7. View Slide

  8. View Slide

  9. github.com/sdras/awesome-actions#community-resources

    View Slide

  10. View Slide

  11. github.com/simonw/simonw/

    View Slide

  12. Open Source Projects using GitHub actions
    (incomplete list)

    View Slide

  13. View Slide

  14. Matrix - Builds auf Linux, macOS, Windows
    strategy:
    fail-fast: false
    matrix:
    os: [macOS-10.14,
    ubuntu-18.04]
    goos: [linux, darwin]
    exclude:
    - os: macOS-10.14
    goos: linux
    - os: ubuntu-18.04
    goos: darwin
    runs-on: ${{ matrix.os }}
    @lothar_schulz

    View Slide

  15. Matrix - Excludes
    strategy:
    fail-fast: false
    matrix:
    os: [macOS-10.14,
    ubuntu-18.04]
    goos: [linux, darwin]
    exclude:
    - os: macOS-10.14
    goos: linux
    - os: ubuntu-18.04
    goos: darwin
    runs-on: ${{ matrix.os }}
    exclude:
    - os: macOS-10.14
    goos: linux
    - os: ubuntu-18.04
    goos: darwin
    @lothar_schulz

    View Slide

  16. Matrix - Excludes
    strategy:
    fail-fast: false
    matrix:
    os: [macOS-10.14,
    ubuntu-18.04]
    goos: [linux, darwin]
    exclude:
    - os: macOS-10.14
    goos: linux
    - os: ubuntu-18.04
    goos: darwin
    runs-on: ${{ matrix.os }}
    exclude:
    - os: macOS-10.14
    goos: linux
    - os: ubuntu-18.04
    goos: darwin
    include:
    - os: macOS-10.14
    goos: darwin
    - os: ubuntu-18.04
    goos: linux
    !
    @lothar_schulz

    View Slide

  17. Matrix

    View Slide

  18. Matrix

    View Slide

  19. Matrix

    View Slide

  20. Matrix - Baue nur was Du brauchst (gradle)
    task testMatrix {
    project.afterEvaluate {
    def checkTasks = subprojects.collect {
    it.tasks.findByName("check")
    }.findAll { it != null }
    dependsOn(checkTasks)
    doLast {
    def checkTaskPaths = checkTasks
    .collect { it.path }
    println(JsonOutput.toJson(checkTaskPaths))
    }
    }
    }
    faster parallel github builds
    https://github.com/testcontainers/testcontainers-java/blob/master/gradle/ci-support.gradle#L4-L18
    @lothar_schulz

    View Slide

  21. Matrix - Baue nur was Du brauchst (gradle) 2
    TASKS=$(./gradlew --no-daemon --parallel -q testMatrix)
    echo $TASKS
    echo "::set-output name=matrix::{\"gradle_args\":$TASKS}"
    faster parallel github builds
    https://github.com/testcontainers/testcontainers-java/blob/master/gradle/ci-support.gradle#L4-L18
    @lothar_schulz

    View Slide

  22. Jobs
    Jobs können gleichzeitig und parallel laufen
    oder
    vom Status eines vorherigen Jobs abhängig sein
    und sequentiell laufen.
    build-and-dockerhub-push-if-linux:
    needs: [benchmark, test]
    @lothar_schulz

    View Slide

  23. Conditionals
    if: matrix.os == 'ubuntu-18.04'
    env:
    DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
    DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
    run: |
    d=$(date +%Y-%m-%d)
    tag=$d-${{ matrix.os }}-${{ github.sha }}
    docker build -t lotharschulz/hello-github-actions:$tag .
    docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
    docker push lotharschulz/hello-github-actions:$tag
    @lothar_schulz

    View Slide

  24. Überraschungen
    test:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/[email protected]
    - uses: actions/[email protected]
    with:
    java-version: 11
    - uses: eskatos/[email protected]
    with:
    arguments: test
    - name: test the code
    @lothar_schulz

    View Slide

  25. test:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/[email protected]
    - uses: actions/[email protected]
    with:
    java-version: 11
    - uses: eskatos/[email protected]
    with:
    arguments: test
    # - name: test the code
    Überraschungen
    @lothar_schulz

    View Slide

  26. View Slide

  27. Demo Code

    View Slide

  28. Mehr Informationen

    View Slide

  29. Noch mehr Informationen

    View Slide

  30. View Slide

  31. View Slide