Skip to content

Instantly share code, notes, and snippets.

@int128
Last active January 10, 2020 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save int128/18f5d20a1d860b2c37d3aa2ae681bc3e to your computer and use it in GitHub Desktop.
Save int128/18f5d20a1d860b2c37d3aa2ae681bc3e to your computer and use it in GitHub Desktop.
GitHub Actions to build and push a Docker image to GitHub Packages Registry
name: Build and push the Docker image
on:
push:
paths:
- docker/**
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- run: make -C docker release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#if: github.event.push.ref == 'refs/heads/master'
FROM alpine:3.11
ARG VERSION
#TODO: add steps
VERSION := v1.0.0
IMAGE_NAME := docker.pkg.github.com/octocat/example/example
IMAGE_TAG := $(VERSION)
GITHUB_USERNAME := octocat
.PHONE: build
build: Dockerfile
docker pull $(IMAGE_NAME):$(IMAGE_TAG)
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) --build-arg VERSION=$(VERSION) .
docker run --rm $(IMAGE_NAME):$(IMAGE_TAG) --version
.PHONE: release
release: build
docker login docker.pkg.github.com --username $(GITHUB_USERNAME) --password $(GITHUB_TOKEN)
docker push $(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: clean
clean:
docker rmi $(IMAGE_NAME):$(IMAGE_TAG)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment