Skip to content

Commit cddabc2

Browse files
krutonorgrim
authored andcommitted
Add Docker build action
This will build a docker package and push it to the GitHub package repository.
1 parent 7da1126 commit cddabc2

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
tags:
7+
- v*
8+
pull_request:
9+
branches: [ "master" ]
10+
release:
11+
types: [ "published" ]
12+
workflow_dispatch:
13+
14+
env:
15+
IMAGE_NAME: pg_back
16+
17+
jobs:
18+
buildx:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/[email protected]
27+
28+
- id: prep
29+
if: "startsWith(github.ref, 'refs/tags/v')"
30+
run: |
31+
echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}
32+
33+
- name: Set up QEMU
34+
uses: docker/[email protected]
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/[email protected]
38+
39+
- name: Cache Docker layers
40+
uses: actions/[email protected]
41+
with:
42+
path: /tmp/.buildx-cache
43+
key: ${{ runner.os }}-buildx-${{ github.sha }}
44+
restore-keys: |
45+
${{ runner.os }}-buildx-
46+
47+
- name: Login to GHCR
48+
uses: docker/[email protected]
49+
if: github.event_name != 'pull_request'
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Push to GitHub Packages
56+
uses: docker/[email protected]
57+
with:
58+
context: .
59+
tags: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.prep.outputs.tag || 'latest' }}
60+
push: ${{ github.event_name != 'pull_request' }}
61+
cache-from: type=local,src=/tmp/.buildx-cache
62+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
63+
64+
- name: Move cache
65+
run: |
66+
rm -rf /tmp/.buildx-cache
67+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
68+

0 commit comments

Comments
 (0)