|
1 |
| -name: Create and publish a package |
| 1 | +name: Push Docker Image to GitHub Packages |
2 | 2 | on:
|
3 | 3 | push:
|
4 |
| - branches: ["master"] |
| 4 | + branches: |
| 5 | + - master |
| 6 | + - container |
| 7 | + tags: |
| 8 | + - "*" |
| 9 | + pull_request: |
5 | 10 | env:
|
6 |
| - REGISTRY: ghcr.io |
7 |
| - IMAGE_NAME: ${{ github.repository }} |
| 11 | + IMAGE_NAME: python-snap7 |
| 12 | +# |
8 | 13 | jobs:
|
9 |
| - build-and-push-image: |
10 |
| - runs-on: ubuntu-20.04 |
| 14 | + push: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + packages: write |
| 18 | + contents: read |
| 19 | + # |
11 | 20 | steps:
|
12 |
| - - name: Extract metadata (tags, labels) for Docker |
13 |
| - id: meta |
14 |
| - uses: docker/metadata-action@v5 |
15 |
| - with: |
16 |
| - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up QEMU |
| 24 | + uses: docker/setup-qemu-action@v3 |
| 25 | + |
| 26 | + - name: Set up Docker Buildx |
| 27 | + id: buildx |
| 28 | + uses: docker/setup-buildx-action@v3 |
17 | 29 |
|
18 |
| - - name: Login to GitHub Container Registry |
19 |
| - uses: docker/login-action@v3 |
20 |
| - with: |
21 |
| - registry: ${{ env.REGISTRY }} |
22 |
| - username: ${{ github.actor }} |
23 |
| - password: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + - name: Log in to registry |
| 31 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
24 | 32 |
|
25 |
| - - name: Build container image |
26 |
| - uses: docker/build-push-action@v5 |
27 |
| - with: |
28 |
| - push: true |
29 |
| - tags: ${{ steps.meta.outputs.tags }} |
30 |
| - labels: ${{ steps.meta.outputs.labels }} |
| 33 | + - name: Build and push container image |
| 34 | + run: | |
| 35 | + IMAGE_ID=$(echo ghcr.io/${{ github.repository }} | tr '[A-Z]' '[a-z]') |
| 36 | + # Strip git ref prefix from version |
| 37 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 38 | + # Strip "v" prefix from tag name |
| 39 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 40 | + # when the branch is master, replace master with latest |
| 41 | + [ "$VERSION" == "master" ] && VERSION=latest |
| 42 | + echo IMAGE_ID=$IMAGE_ID |
| 43 | + echo VERSION=$VERSION |
| 44 | + # Build and Publish container image |
| 45 | + docker buildx build --push \ |
| 46 | + --tag $IMAGE_ID:$VERSION \ |
| 47 | + --platform linux/amd64,linux/arm/v7,linux/arm64 . |
0 commit comments