Skip to content

Commit 3e95902

Browse files
authored
test-publish (#3)
* use GITHUB_TOKEN [no ci] * cleanup docker [no ci] * supress warning using uv [no ci] * add git remote, if not set [no ci] * build docker with tag versioning [no ci] * only build in sepecific changes [no ci]
1 parent 0a4cc0f commit 3e95902

3 files changed

Lines changed: 63 additions & 22 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ LABEL org.opencontainers.image.licenses="MIT"
1414

1515

1616
# Install system packages:
17-
# curl
18-
RUN apt-get update && apt-get install -y curl
19-
# gnupg
20-
RUN apt-get update && apt-get install -y gnupg
21-
# git
22-
RUN apt-get update && apt-get install -y git
23-
# unzip
24-
RUN apt-get update && apt-get install -y unzip
25-
# build-essential
26-
RUN apt-get update && apt-get install -y build-essential
27-
# libsqlite3-dev
28-
RUN apt-get update && apt-get install -y libsqlite3-dev
17+
RUN apt-get update && apt-get install -y \
18+
curl \
19+
gnupg \
20+
git \
21+
unzip \
22+
build-essential \
23+
libsqlite3-dev \
24+
&& rm -rf /var/lib/apt/lists/*
2925
# duckdb
3026
RUN curl -sL https://install.duckdb.org | sh && \
3127
mkdir -p /usr/local/bin && \

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
"files.insertFinalNewline": true,
2424
"files.trimFinalNewlines": true,
2525
"files.autoSave": "afterDelay",
26+
"terminal.integrated.env.linux": {
27+
"UV_LINK_MODE": "copy"
28+
}
2629
}
2730
}
2831
},
29-
"postCreateCommand": "uv venv --force && uv sync -v",
32+
"postCreateCommand": "uv venv --force && uv sync -v && if ! git remote | grep origin; then repo=$(basename $(pwd)); git remote add origin https://github.com/EED-Solutions/$repo.git; fi",
3033
"features": {},
3134
"remoteUser": "vscode"
3235
}

.github/workflows/publish_docker.yml

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ name: Publish Docker Image to GHCR
22

33
on:
44
workflow_dispatch:
5-
# push:
6-
# branches: [main]
7-
# paths:
8-
# - '.devcontainer/Dockerfile'
9-
# - '.github/workflows/publish.yml'
5+
push:
6+
branches:
7+
- main
8+
- release
9+
- dev
10+
tags:
11+
- 'v*.*.*' # Semantic versioning pattern
1012

1113
permissions:
1214
contents: read
@@ -24,10 +26,50 @@ jobs:
2426
with:
2527
registry: ghcr.io
2628
username: ${{ github.actor }}
27-
password: ${{ secrets.GH_PAT }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
2830

2931
- name: Build and push Docker image
3032
run: |
31-
IMAGE_NAME=ghcr.io/eed-solutions/eed_docker_python_uv:latest
32-
docker build -t $IMAGE_NAME -f .devcontainer/Dockerfile .
33-
docker push $IMAGE_NAME
33+
IMAGE_NAME=ghcr.io/eed-solutions/eed_docker_python_uv
34+
TAG=latest
35+
SHOULD_BUILD_PUSH=false
36+
37+
# Determine tag and build indicator based on context
38+
if [[ "${{ github.ref_type }}" == "branch" ]]; then
39+
case "${{ github.ref_name }}" in
40+
"main")
41+
TAG=main
42+
SHOULD_BUILD_PUSH=true
43+
;;
44+
"dev")
45+
TAG=dev
46+
SHOULD_BUILD_PUSH=true
47+
;;
48+
"release")
49+
TAG=release
50+
SHOULD_BUILD_PUSH=true
51+
;;
52+
*)
53+
TAG=${{ github.ref_name }}
54+
;;
55+
esac
56+
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
57+
TAG=${{ github.ref_name }}
58+
if [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
59+
SHOULD_BUILD_PUSH=true
60+
fi
61+
fi
62+
63+
# Build and push the image if indicated
64+
if [[ "$SHOULD_BUILD_PUSH" == "true" ]]; then
65+
docker build -t $IMAGE_NAME:$TAG -f .devcontainer/Dockerfile .
66+
docker push $IMAGE_NAME:$TAG
67+
else
68+
echo "Skipping build and push: not a main/dev/release branch or semantic version tag."
69+
fi
70+
71+
# Push additional 'latest' tag for semantic version tags
72+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
73+
docker tag $IMAGE_NAME:$TAG $IMAGE_NAME:latest
74+
docker push $IMAGE_NAME:latest
75+
fi

0 commit comments

Comments
 (0)