Skip to content

Commit 8008899

Browse files
authored
Add dockerfile and docker packaging automation (#8)
1 parent 626d088 commit 8008899

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

.github/workflows/package.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,28 @@ jobs:
3838
file: ./coverage.xml
3939
name: gitea_github_sync
4040
flags: unittests
41+
build-docker:
42+
runs-on: ubuntu-latest
43+
defaults:
44+
run:
45+
shell: bash
46+
steps:
47+
- uses: actions/checkout@v2
48+
- name: Docker metadata
49+
id: meta
50+
uses: docker/metadata-action@v4
51+
with:
52+
images: muscaw/gitea-github-sync
53+
tags: |
54+
type=ref,event=branch
55+
type=ref,event=pr
56+
type=semver,pattern={{version}}
57+
type=semver,pattern={{major}}.{{minor}}
58+
- name: Build docker image
59+
uses: docker/build-push-action@v3
60+
with:
61+
context: .
62+
file: ./Dockerfile
63+
push: false
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@ on:
88
jobs:
99
call-build:
1010
uses: ./.github/workflows/package.yml
11+
build-docker:
12+
needs: call-build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v2
18+
- name: Docker metadata
19+
id: meta
20+
uses: docker/metadata-action@v4
21+
with:
22+
images: muscaw/gitea-github-sync
23+
tags: |
24+
type=ref,event=branch
25+
type=ref,event=pr
26+
type=semver,pattern={{version}}
27+
type=semver,pattern={{major}}.{{minor}}
28+
- name: Login to Docker Hub
29+
uses: docker/login-action@v2
30+
with:
31+
username: ${{ secrets.DOCKERHUB_USERNAME }}
32+
password: ${{ secrets.DOCKERHUB_TOKEN }}
33+
- name: Build and push docker image
34+
uses: docker/build-push-action@v3
35+
with:
36+
context: .
37+
file: ./Dockerfile
38+
push: true
39+
tags: ${{ steps.meta.outputs.tags }}
40+
labels: ${{ steps.meta.outputs.labels }}
1141
publish-to-pypi:
1242
needs: call-build
1343
runs-on: ubuntu-latest

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.11
2+
3+
RUN useradd -m python-user
4+
USER python-user
5+
6+
WORKDIR /app
7+
8+
ENV PATH="${PATH}:/home/python-user/.local/bin/"
9+
10+
COPY gitea_github_sync/ /app/gitea_github_sync
11+
COPY README.md poetry.lock pyproject.toml /app/
12+
COPY docker/config.yml /home/python-user/.config/gitea-github-sync/config.yml
13+
14+
RUN pip install poetry && poetry install
15+
16+
ENTRYPOINT ["poetry", "run", "python", "-m", "gitea_github_sync"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ gitea-github-sync provides a simple CLI to sync Github repositories to your Gite
88
pip install gitea-github-sync
99
```
1010

11+
If you are interested in using a pre-packaged docker image, please look at the [Docker Readme](docs/docker/README.md)
12+
1113
## Setup
1214
Create a file in `$HOME/.config/gitea-github-sync/config.yml` with the following template and fill up the missing values:
1315

docker/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
gitea_api_url: ${GITEA_API_URL}
2+
gitea_token: ${GITEA_TOKEN}
3+
github_token: ${GITHUB_TOKEN}

docs/docker/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# gitea-github-sync docker image
2+
3+
gitea-github-sync is automatically packaged in a docker image and can be pulled with the following command:
4+
5+
`docker pull muscaw/gitea-github-sync:latest`
6+
7+
## Setup
8+
9+
### Setup using environment variables
10+
11+
The docker image contains a configuration file that uses environment variables to configure gitea-github-sync.
12+
13+
You can create a file called _.env_ with the following content:
14+
15+
```
16+
GITHUB_TOKEN=<your-github-token>
17+
GITEA_API_URL=https://<your-gitea-url>/api/v1
18+
GITEA_TOKEN=<your-gitea-token>
19+
```
20+
21+
Run the docker image with the env file:
22+
23+
`docker run --rm --env-file .env muscaw/gitea-github-sync:latest sync`
24+
25+
### Mount a configuration file
26+
27+
Create the config.yml file wherever you want and mount it in the docker container:
28+
29+
`docker run --rm -v <location-of-config.yml>:/home/python-user/.config/gitea-github-sync/config.yml muscaw/gitea-github-sync:latest sync`

0 commit comments

Comments
 (0)