Skip to content

Instantly share code, notes, and snippets.

@jonico
Created August 19, 2019 07:22
Show Gist options
  • Save jonico/e18127b487d198606e31aac669262af8 to your computer and use it in GitHub Desktop.
Save jonico/e18127b487d198606e31aac669262af8 to your computer and use it in GitHub Desktop.
Build docker image and push to GPR with GitHub Actions
name: Build and publish Jekyll Docker image for Octocat Generator
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: clean up, docker login && docker build && docker push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPR_PAT: ${{ secrets.GPR_PAT }}
run: |
./cleanup.sh
docker login -u ${GITHUB_ACTOR} -p ${GPR_PAT} docker.pkg.github.com
docker build -t docker.pkg.github.com/${GITHUB_REPOSITORY}/octocat-generator:v-${GITHUB_SHA} .
curl -s -H "Authorization: Token ${GITHUB_TOKEN}" -H "Accept: application/json" -H "Content-type: application/json" -X POST -d "{ \"ref\": \"refs/tags/v-${GITHUB_SHA}\", \"sha\": \"${GITHUB_SHA}\"}" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/refs
docker push docker.pkg.github.com/${GITHUB_REPOSITORY}/octocat-generator:v-${GITHUB_SHA}
@mpdude
Copy link

mpdude commented Jan 15, 2020

And that curl line is about creating a tag?

@jonico
Copy link
Author

jonico commented Jan 15, 2020

What do you need ${GPR_PAT} for?

GITHUB_TOKEN, at least when I wrote this snippet, did not have the scope to publish a docker image

@jonico
Copy link
Author

jonico commented Jan 15, 2020

And that curl line is about creating a tag?

Yes, to associate the created docker image with a specific tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment