Merge pull request #6 from rene00/container-build
improve github build action
-name: Build and publish container
-
-on:
- push:
- branches:
- - main
-
-env:
- IMAGE_NAME: aircon-influx
- IMAGE_TAG: latest
- CONTAINER_REGISTRY: ghcr.io
-
-jobs:
- build-and-publish:
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout code
- uses: actions/checkout@v2
-
- - name: Install Podman
- run: |
- sudo apt-get update
- sudo apt-get -y install podman
-
- - name: Login to Container Registry
- run: echo ${{ secrets.GITHUB_TOKEN }} | podman login ${{ env.CONTAINER_REGISTRY }} -u ${{ github.actor }} --password-stdin
-
- - name: Build container
- run: podman build -t ${CONTAINER_REGISTRY}/${{ github.repository }}/${IMAGE_NAME}:${IMAGE_TAG} .
-
- - name: Push container
- run: podman push ${CONTAINER_REGISTRY}/${{ github.repository }}/${IMAGE_NAME}:${IMAGE_TAG}
+name: container
+
+on:
+ workflow_dispatch:
+ push:
+ branches:
+ - 'main'
+ tags:
+ - 'v*'
+ pull_request:
+ branches:
+ - 'main'
+
+env:
+ REGISTRY_USER: ${{ github.actor }}
+ REGISTRY_PASSWORD: ${{ github.token }}
+ IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
+
+jobs:
+ build-and-push-image:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ packages: write
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+
+ - name: Docker meta
+ id: docker-metadata
+ uses: docker/metadata-action@v4
+ with:
+ images: ghcr.io/${{ github.actor }}/aircon-influx
+
+ - name: Build Image
+ id: build-image
+ uses: redhat-actions/buildah-build@v2
+ with:
+ image: aircon-influx
+ tags: ${{ steps.docker-metadata.outputs.tags }}
+ labels: ${{ steps.docker-metadata.outputs.labels }}
+ containerfiles: |
+ ./Containerfile
+ extra-args: |
+ --pull
+
+ - name: Log in to the Container Registry
+ uses: docker/login-action@v2
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Push to Container Registry
+ uses: redhat-actions/push-to-registry@v2
+ with:
+ image: ${{ steps.build-image.outputs.image }}
+ tags: ${{ steps.build-image.outputs.tags }}
+ registry: ghcr.io/${{ github.actor }}
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}