[Golang] Create docker image with Github Actions

Contents

Create a Docker image of your Golang app and push it to the Docker registry. Click here for the Dockerfile for the Golang app (https://qiita.com/Yuuki557/items/3d088de91ab86bc71600)

table of contents

--Workflow file --Capturing the contents

Workflow file

ci.yaml


name: CI
on:
  push:
    tags:
      - "v*.*.*"

jobs:
  test:
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        go: ["1.15"]
    steps:
      - name: Check out source code
        uses: actions/checkout@v1
        
      - name: Set up Go v${{matrix.go}}
        uses: actions/setup-go@v2
        with:
          go-version: ${{matrix.go}}

      - name: Install dependent packages
        run: go mod download

      - name: Run all test
        run: go test -v ./...

  docker-build:
    needs: ["test"]
    runs-on: ubuntu-18.04
    env:
      DOCKER_IMAGE_NAME: docker-app
    steps:
      - name: Check out source code
        uses: actions/checkout@v1

      - name: Build and push docker image
        run: |
          TAG=$(echo $GITHUB_REF | grep -o "[0-9][\.].*")
          DOCKER_IMAGE=${{ secrets.DOCKER_REGISTRY }}/${DOCKER_IMAGE_NAME}:$TAG
          echo "Docker image: ${DOCKER_IMAGE}"
          docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }}
          docker build -t $DOCKER_IMAGE .
          docker push $DOCKER_IMAGE

Content capture

Workflow triggers --on.push.tags

It is triggered by a push in the form of tag v1.0.0. There are many triggers besides push.

Test --jobs.test

The following contents are done in order

  1. Check out the source code
  2. Specify the version of Golang (specify 1.15 this time)
  3. Install dependent packages according to * go modules * (go mod download)
  4. Run all tests in the working directory (go test -v ./...)

Image build and push --jobs.docker-build

The following contents are done in order

  1. Creating an image tag from git ref (eg v1.0.0-> 1.0.0)
  2. Create a Docker image name (registry name is secret, image name is env, tag name is 1)
  3. Log in to docker (username and password are secret)
  4. docker build (Docker image name was created in 2)
  5. docker push

Recommended Posts

[Golang] Create docker image with Github Actions
Steps to create a Job that pulls a Docker image and tests it with Github Actions
Tested pipenv with GitHub Actions
Create github pages with lektor Part 1
Create a Docker container image with JRE8 / JDK8 on Amazon Linux
Create an image processing viewer with PySimpleGUI
Create a dummy image with Python + PIL.
Create Python + uWSGI + Nginx environment with Docker
Create a web service with Docker + Flask
Create polka dot wallpaper with Python Image Library
Create an image composition app with Flask + Pillow
Create Nginx + uWSGI + Python (Django) environment with docker
Create an image with characters in python (Japanese)
Build a Docker image containing the private repository Python library on GitHub Actions
Resize multipart.File type image with golang ~ Upload to S3
Create a Layer for AWS Lambda Python with Docker
Create miscellaneous Photoshop videos with Python + OpenCV ② Create still image Photoshop
[Linux] Create a self-signed certificate with Docker and apache
Image processing with MyHDL
Expose your Docker image
Image recognition with keras
Getting Started with Golang 2
Getting Started with Golang 1
Use python with docker
Create games with Pygame
Proxy server with Docker
Create filter with scipy
Image processing with Python
Getting Started with Golang 3
Call bash with golang
Getting Started with Golang 4
Jupyter Docker image summary
Image Processing with PIL
Create an environment for "Deep Learning from scratch" with Docker
Creating an environment that automatically builds with Github Actions (Android)
Create a simple Python development environment with VSCode & Docker Desktop
Deploy your Go app on Google App Engine with GitHub Actions
Build GPU environment with GCP and kaggle official image (docker)
Create a GCE instance from a GCR Docker image using terraform
Create a Todo app with Django ① Build an environment with Docker
[With image diagram] Nginx + gunicorn + Flask converted to Docker [Part 1]