Skip to content

Commit 5fcc155

Browse files
committed
rearrange files; reduce dockerfile
* Files rearranged * Dockerfile cleaned up * fewer layers * works * specific version for update purposes * no install/upgrade of pip (more deterministic) * pinned versions in requirements.txt * docker-compose added for build / run with sample file * github actions automations which may or may not work as planned
1 parent 32e1c34 commit 5fcc155

21 files changed

+289
-20
lines changed

.github/dependabot.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
# Basic set up for three package managers
3+
version: 2
4+
updates:
5+
6+
# Maintain dependencies for GitHub Actions
7+
- package-ecosystem: github-actions
8+
directory: /
9+
schedule:
10+
interval: daily
11+
12+
# Maintain dependencies for python
13+
- package-ecosystem: pip
14+
directory: /
15+
schedule:
16+
interval: daily
17+
18+
# Maintain dependencies for Docker
19+
- package-ecosystem: docker
20+
directory: /
21+
schedule:
22+
interval: daily

.github/workflows/auto_action.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Auto Actions
3+
4+
on: # yamllint disable-line rule:truthy
5+
pull_request_target:
6+
types: [labeled, unlabeled, synchronize, review_requested, opened, reopened]
7+
8+
permissions:
9+
pull-requests: write
10+
contents: write
11+
12+
jobs:
13+
auto-approve-github-actions:
14+
runs-on: ubuntu-latest
15+
if: >-
16+
github.actor == 'dependabot[bot]'
17+
||
18+
github.actor == 'dependabot-preview[bot]'
19+
steps:
20+
- uses: hmarr/[email protected]
21+
with:
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
auto-merge-github-actions:
25+
runs-on: ubuntu-latest
26+
if: >-
27+
github.actor == 'dependabot[bot]'
28+
||
29+
github.actor == 'dependabot-preview[bot]'
30+
steps:
31+
- name: Enable auto-merge
32+
run: gh pr merge --auto --squash "$PR_URL"
33+
env:
34+
PR_URL: ${{github.event.pull_request.html_url}}
35+
#GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}
36+
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}

.github/workflows/release.yml

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
---
2+
name: release
3+
on: # yamllint disable-line rule:truthy
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
env:
11+
IMAGE_NAME: ${{ github.repository_owner }}/ldap_sync
12+
EXCHANGE_PATH: /tmp
13+
EXCHANGE_FILE: image.tar
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
env:
19+
BUILD_TAG: ${{ github.job }}.${{ github.run_id }}
20+
outputs:
21+
tag: ${{ env.BUILD_TAG }}
22+
permissions:
23+
contents: read
24+
steps:
25+
- name: work around github's inability to add a lowercase() function
26+
run: |
27+
echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v2
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v2
32+
#- name: Log in to GitHub Container Registry
33+
# uses: docker/login-action@v2
34+
# with:
35+
# registry: ghcr.io
36+
# username: ${{ github.repository_owner }}
37+
# password: ${{ secrets.GITHUB_TOKEN }}
38+
- name: Build Docker image
39+
uses: docker/build-push-action@v3
40+
with:
41+
push: false
42+
# note: because this image is exported, we can only build one platform here
43+
platforms: linux/amd64
44+
tags: ${{ env.LC_IMAGE_NAME }}:${{ env.BUILD_TAG }}
45+
#tags: ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ env.BUILD_TAG }}
46+
#cache-from: type=registry,ref=ghcr.io/${{ env.LC_IMAGE_NAME }}:latest
47+
#cache-to: type=inline
48+
cache-from: type=gha
49+
cache-to: type=gha,mode=max
50+
outputs: type=docker,dest=${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
51+
- name: Upload artifact
52+
uses: actions/upload-artifact@v3
53+
with:
54+
name: ${{ env.EXCHANGE_FILE }}
55+
path: ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
56+
57+
test_docker_run:
58+
runs-on: ubuntu-latest
59+
needs: build
60+
permissions:
61+
contents: read
62+
steps:
63+
- name: work around github's inability to add a lowercase() function
64+
run: |
65+
echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
66+
- name: Download artifact
67+
uses: actions/download-artifact@v3
68+
with:
69+
name: ${{ env.EXCHANGE_FILE }}
70+
path: ${{ env.EXCHANGE_PATH }}
71+
- name: Load image
72+
run: |
73+
docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
74+
docker image ls -a
75+
- name: run test
76+
env:
77+
SOMEVAR: someval
78+
run:
79+
docker run --rm -i $LC_IMAGE_NAME:${{ needs.build.outputs.tag }} /bin/echo "yay"
80+
81+
# TODO: add an actual test of the image :facepalm:
82+
test_actual_python:
83+
runs-on: ubuntu-latest
84+
needs: build
85+
permissions:
86+
contents: read
87+
steps:
88+
- name: work around github's inability to add a lowercase() function
89+
run: |
90+
echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
91+
- name: Download artifact
92+
uses: actions/download-artifact@v3
93+
with:
94+
name: ${{ env.EXCHANGE_FILE }}
95+
path: ${{ env.EXCHANGE_PATH }}
96+
- name: Load image
97+
run: |
98+
docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
99+
docker image ls -a
100+
- name: run test
101+
env:
102+
SOMEVAR: someval
103+
run:
104+
docker run --rm -i $LC_IMAGE_NAME:${{ needs.build.outputs.tag }} /bin/echo "yay"
105+
106+
release:
107+
runs-on: ubuntu-latest
108+
needs:
109+
- build
110+
- test_docker_run
111+
- test_actual_python
112+
if: ${{ github.ref == 'refs/heads/main' && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch' ) }}
113+
permissions:
114+
contents: write
115+
actions: read
116+
checks: read
117+
packages: write
118+
steps:
119+
- name: work around github's inability to add a lowercase() function
120+
run: |
121+
echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
122+
123+
# create the release
124+
- name: Checkout
125+
uses: actions/[email protected]
126+
with:
127+
fetch-depth: 0 # need all refs for tag generation
128+
- name: Auto Increment Semver Action
129+
uses: MCKanpolat/[email protected]
130+
id: versioning
131+
with:
132+
releaseType: patch
133+
# this is a read-only action, I think, so either token is ok
134+
github_token: ${{ secrets.GITHUB_TOKEN }}
135+
- name: Commit back
136+
uses: actions-js/push@master
137+
with:
138+
# commit back with Github token to avoid retriggering actions
139+
github_token: ${{ secrets.GITHUB_TOKEN }}
140+
message: Release ${{ steps.versioning.outputs.version }}
141+
branch: main
142+
- name: Create Github Release
143+
uses: ncipollo/[email protected]
144+
if: steps['versioning']['outputs']['RETURN_STATUS'] == '0'
145+
with:
146+
tag: ${{ steps.versioning.outputs.version }}
147+
name: ${{ steps.versioning.outputs.version }}
148+
generateReleaseNotes: True
149+
#body: Version ${{ steps.versioning.outputs.version }}
150+
draft: false
151+
prerelease: false
152+
# # release with PAT to trigger actions on release
153+
# token: ${{ secrets.ACTION_TOKEN }}
154+
155+
# rebuild the container after (we need to know the tag, but we know
156+
# this will work because it worked in the job we depend upon)
157+
- name: Set up QEMU
158+
uses: docker/setup-qemu-action@v2
159+
- name: Set up Docker Buildx
160+
uses: docker/setup-buildx-action@v2
161+
- name: Log in to GitHub Container Registry
162+
uses: docker/login-action@v2
163+
with:
164+
registry: ghcr.io
165+
username: ${{ github.repository_owner }}
166+
password: ${{ secrets.GITHUB_TOKEN }}
167+
# - name: Login to DockerHub
168+
# uses: docker/[email protected]
169+
# with:
170+
# username: ${{ secrets.DOCKER_USERNAME }}
171+
# password: ${{ secrets.DOCKER_PASSWORD }}
172+
- name: Download artifact
173+
uses: actions/download-artifact@v3
174+
with:
175+
name: ${{ env.EXCHANGE_FILE }}
176+
path: ${{ env.EXCHANGE_PATH }}
177+
- name: Load image
178+
run: |
179+
docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
180+
docker image ls -a
181+
- name: Build Docker image
182+
uses: docker/build-push-action@v3
183+
with:
184+
push: true
185+
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
186+
tags: |
187+
ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }}
188+
ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ steps.versioning.outputs.version }}
189+
ghcr.io/${{ env.LC_IMAGE_NAME }}:latest
190+
#tags: |
191+
# ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }}
192+
# ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ steps.versioning.outputs.version }}
193+
# ghcr.io/${{ env.LC_IMAGE_NAME }}:latest
194+
# ${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }}
195+
# ${{ env.LC_IMAGE_NAME }}:${{ steps.versioning.outputs.version }}
196+
# ${{ env.LC_IMAGE_NAME }}:latest
197+
#cache-from: type=registry,ref=ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }}
198+
#cache-to: type=inline

Dockerfile

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
1+
# syntax = docker/dockerfile:1.3
22
# Use the official Python 3 image.
33
# https://hub.docker.com/_/python
4-
5-
FROM python:3.8-slim
4+
FROM python:3.8.16-slim
65

7-
RUN apt-get -y update
8-
RUN apt-get -y install libsasl2-dev python-dev libldap2-dev libssl-dev
9-
RUN apt-get -y install pip
10-
11-
RUN /usr/local/bin/python -m pip install --upgrade pip
12-
13-
COPY ./ldap_sync.py /ldap_sync/
14-
COPY ./libs /ldap_sync/libs
15-
COPY ./plugins /ldap_sync/plugins
16-
17-
COPY ./requirements.txt /ldap_sync/requirements.txt
18-
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
RUN apt-get -y update \
8+
&& apt-get -y install \
9+
libsasl2-dev \
10+
build-essential \
11+
python-dev \
12+
libldap2-dev \
13+
libssl-dev \
14+
&& apt-get -y clean
15+
16+
COPY ldap_sync/ /ldap_sync/
1917
WORKDIR /ldap_sync
2018

21-
RUN chmod 444 requirements.txt
22-
19+
ARG CONFIGDIR=/etc/determined
20+
RUN mkdir -p $CONFIGDIR \
21+
&& chmod 0755 $CONFIGDIR \
22+
&& chmod 0444 requirements.txt
2323
RUN pip install --no-cache-dir -r requirements.txt
2424

2525
# Run the web service on container startup.

docker-compose.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: "3.0"
3+
services:
4+
ldap_sync:
5+
build: .
6+
volumes:
7+
- ./config.yaml:/etc/determined/ldap_sync_config.yaml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ldap_sync/requirements.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PyYAML==6.0
2+
requests==2.28.2
3+
python-ldap==3.4.3
4+
urllib3==1.26.14
5+
certifi==2022.12.7
6+
charset-normalizer==3.0.1
7+
idna==3.4
8+
pyasn1==0.4.8
9+
pyasn1-modules==0.2.8

requirements.txt

-3
This file was deleted.

0 commit comments

Comments
 (0)