• Stars
    star
    135
  • Rank 268,300 (Top 6 %)
  • Language Makefile
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Docker GitHub Action Example

Main Branch CI Nightly Test

Welcome. This is a simple example application to show a common Docker specific GitHub Action setup. We have a Python Flask application that is built and deployed in Docker containers using Dockerfiles and Docker Compose.

Docker Actions v2

CI Setup

We want to setup CI to test:

We are going to use GitHub Actions for the CI infrastructure. Since its local to GitHub Actions and free when used inside GitHub Actions we're going to use the new GitHub Container Registry to hold a copy of a nightly Docker image.

After CI when it comes time for production we want to use Docker's new Amazon ECS integration to deploy from Docker Compose directly to Amazon ECS with Fargate. So we will push our release tagged images to Docker Hub which is integrated directly Amazon ECS via Docker Compose.

The Dockerfile is setup to use multi stage builds. We have stages for test and prod. This means we'll need Docker Buildx and we can use the a preview of the new Docker Buildx Action. This is going to let us achieve a couple awesome outcomes:

  • We are going to use the buildx backend by default. Buildx out of the box brings a number of improvements over the default docker build. Here.
  • We are going to setup buildx caching to take advantage of the GitHub Action Cache. You should see build performance improvements when repeating builds with common layers. Here. Here.
  • We are going to setup QEMU to do cross platform builds. In the example, we'll build this application for every Linux architecture that Docker Hub supports. Here. Here.

I'm not going to have GitHub Action manage the deployment side of this example. Mostly because I don't want to leave an Amazon ECS cluster running. But you can see a demo of this in one of my past streams: https://www.youtube.com/watch?v=RfQrgZFq_P0

GitHub Container Registry FAQ

I thought GHCR had anonymous pulls?

Its a beta product so the documentation doesn't really exist yet. If you dig around on GitHub's Community site you can find some answers. Thats a pain so here is what I've found.

ghcr.io is private by default. You'll notice in the nightly.yml I had to do a login to be able to pull the image.

You can see what packages you have by going here (change the username): https://github.com/USERNAME?tab=packages&visibility=private

You can make it public going to the packages settings (change the username and project name): https://github.com/users/USERNAME/packages/container/PROJECTNAME/settings

Compose sample application

Python/Flask application

Project structure:

.
├── docker-compose.yaml
├── app
    ├── Dockerfile
    ├── requirements.txt
    └── app.py

docker-compose.yaml

services:
  web:
    build: app
    ports:
      - '5000:5000'

Deploy with docker-compose

$ docker-compose up -d
Creating network "flask_default" with the default driver
Building web
Step 1/6 : FROM python:3.7-alpine
...
...
Status: Downloaded newer image for python:3.7-alpine
Creating flask_web_1 ... done

Expected result

Listing containers must show one container running and the port mapping as below:

$ docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                  NAMES
c126411df522        flask_web                    "python3 app.py"         About a minute ago  Up About a minute   0.0.0.0:5000->5000/tcp flask_web_1

After the application starts, navigate to http://localhost:5000 in your web browser or run:

$ curl localhost:5000
Hello Docker and GitHub!

Stop and remove the containers

$ docker-compose down

Troubleshooting

The most common error we have seen in the issues is a build failure with the error:

buildx failed with: error: unable to prepare context: path "./yourprojectfolder" not found

This is due to some issue with access to the code. Often the code has not been checked out. Its important to remember that GitHub Actions do not automatically check out a copy of the project. You will need to use the checkout action. For example:

- name: Checkout
  uses: actions/checkout@v2

More Repositories

1

changelog-generator

GitHub Action to generate changelogs, release notes, whatever
JavaScript
137
star
2

docker-ecs-compose

HTML
21
star
3

docker-circleci-example

Makefile
6
star
4

dotfiles

Shell
3
star
5

earthly-python-example

An Python Flask app built with Earthly
Makefile
2
star
6

dagger-hello

Go
2
star
7

bashpod

One stop shop for Bash centric dotfiles for Gitpod, WSL, and Mac
Shell
2
star
8

ubuntu-box

Shell
2
star
9

gpsh

Shell
2
star
10

gitpod-helpers

Helpers for installing self-hosted Gitpod
Shell
2
star
11

gitpod-py-centos

Python
2
star
12

clever

TypeScript
1
star
13

ender3v2

G-code
1
star
14

slacker-bash

Simple wrapper for my favorite Slack CLI commands
Shell
1
star
15

hub-cli

Docker Hub Repo Create/Delete
JavaScript
1
star
16

demo-podman

1
star
17

gmail-cleanup-script

Google Script App to keep Gmail clean
JavaScript
1
star
18

docker-simple-flask

HTML
1
star
19

secscanblob

Python
1
star
20

composer

Python
1
star
21

rocktreemountain

SCSS
1
star
22

myexample

Go
1
star
23

dotcloud

Lightweight dotfiles for remote cloud environments like Codespaces and Daytona.
Shell
1
star
24

gitpod-docs-test

HTML
1
star
25

compose-workaround

Can we work around the Docker Compose shutdown issue?
Shell
1
star
26

easy-button-main

Change a GitHub repository's default branch from the CLI
Ruby
1
star
27

slacker

Slacker in Go
Go
1
star
28

sbtest

Created with StackBlitz ⚡️
Vue
1
star
29

golang-template

Go
1
star
30

cloud-ranges

Python Script to Get AWS, GCP, and Azure IP ranges
Python
1
star
31

jumpbox

VPN/Mosh Dev Env on Digital Ocean
HCL
1
star
32

newdot

New Dotfiles
Shell
1
star
33

two-build-pushes

Dockerfile
1
star
34

minecraft

1
star
35

docker-artifactory-hol

Docker Artifactory Hands on Lab
Shell
1
star
36

gitpod-this

A cross Linux script to do all the things that Gitpod workspaces need
Shell
1
star
37

metcalfc

Chad Metcalf
1
star
38

tailzone

Create a BIND Zone from the devices in a Tailscale account
Python
1
star
39

stevedore

A common Vagrant environment for developing, testing or playing with the Docker ecosystem.
Shell
1
star