Skip to content

Commit 280438a

Browse files
author
Kendall
authored
Create build-and-push.yaml
1 parent 3356eff commit 280438a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/workflows/build-and-push.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Push
2+
on:
3+
push:
4+
branches: [main]
5+
# Publish semver tags as releases.
6+
tags: ["v*.*.*"]
7+
workflow_dispatch:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v2
22+
23+
# Login against a Docker registry except on PR
24+
# https://github.com/docker/login-action
25+
- name: Log into registry ${{ env.REGISTRY }}
26+
if: github.event_name != 'pull_request'
27+
uses: docker/login-action@v1
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN}}
32+
33+
# Extract metadata (tags, labels) for Docker
34+
# https://github.com/docker/metadata-action
35+
- name: Extract Docker metadata
36+
id: meta
37+
uses: docker/metadata-action@v3
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=semver,pattern={{major}}
44+
type=ref,event=branch
45+
type=sha
46+
# Build and push Docker image with Buildx (don't push on PR)
47+
# https://github.com/docker/build-push-action
48+
- name: Build and push Docker image
49+
uses: docker/build-push-action@v2
50+
with:
51+
context: ./src
52+
push: ${{ github.event_name != 'pull_request' }}
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)