Skip to content

Commit 004f60d

Browse files
authored
update container workflow (gijzelaerr#509)
* update container workflow * try again
1 parent 8897dd4 commit 004f60d

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

.github/workflows/docker.yml

+40-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
name: Create and publish a package
1+
name: Push Docker Image to GitHub Packages
22
on:
33
push:
4-
branches: ["master"]
4+
branches:
5+
- master
6+
- container
7+
tags:
8+
- "*"
9+
pull_request:
510
env:
6-
REGISTRY: ghcr.io
7-
IMAGE_NAME: ${{ github.repository }}
11+
IMAGE_NAME: python-snap7
12+
#
813
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+
#
1120
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
1729

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
2432

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 .

Dockerfile

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:24.04
22
ENV DEBIAN_FRONTEND=noninteractive
3+
4+
LABEL org.opencontainers.image.source=https://github.com/gijzelaerr/python-snap7
5+
LABEL org.opencontainers.image.description="The snap7 library is used to communicate with Siemens S7 PLCs. This is a Python wrapper for the snap7 library."
6+
LABEL org.opencontainers.image.licenses=MIT
7+
38
RUN apt update \
4-
&& apt install -y software-properties-common python3-pip \
9+
&& apt install -y software-properties-common python3-pip python3-venv \
510
&& add-apt-repository ppa:gijzelaar/snap7 \
611
&& apt update \
712
&& apt install -y libsnap7-dev libsnap7-1
813
ADD . /code
9-
WORKDIR /code
10-
RUN pip3 install .
14+
WORKDIR /venv
15+
RUN python3 -m venv /venv
16+
RUN . /venv/bin/activate
17+
RUN /venv/bin/pip install /code

0 commit comments

Comments
 (0)