Skip to content

Commit

Permalink
Added Github Actions automatic Docker image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
omerkarabacak committed Sep 20, 2021
1 parent e5a9264 commit d018ccf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Demo Push

on:
push:
branches:
- master

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: bulk-find-and-replace-in-git-repositories

jobs:
push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ You can build your Docker image with Dockerfile or use ready public Docker image
#### Option 1: Build your own Docker image and use it
Build Docker image:
```ssh
docker build -t bulk-find-and-replace-in-git-repositories:1.0 .
docker build -t bulk-find-and-replace-in-git-repositories:1.1 .
```
Run with built local Docker image:
```ssh
docker run --rm -v $(pwd)/config.json:/app/config.json -v $(pwd)/repositories:/app/repositories -v ~/.ssh/id_rsa:/root/.ssh/id_rsa bulk-find-and-replace-in-git-repositories:1.0
docker run --rm -v $(pwd)/config.json:/app/config.json -v $(pwd)/repositories:/app/repositories -v ~/.ssh/id_rsa:/root/.ssh/id_rsa bulk-find-and-replace-in-git-repositories:1.1
```
#### Option 2: Use public Docker image hosted on Docker Hub
Run with public Docker image:
```ssh
docker run --rm -v $(pwd)/config.json:/app/config.json -v $(pwd)/repositories:/app/repositories -v ~/.ssh/id_rsa:/root/.ssh/id_rsa omerkarabacak/bulk-find-and-replace-in-git-repositories:1.0
docker run --rm -v $(pwd)/config.json:/app/config.json -v $(pwd)/repositories:/app/repositories -v ~/.ssh/id_rsa:/root/.ssh/id_rsa ghcr.io/omerkarabacak/bulk-find-and-replace-in-git-repositories:1.1
```
### How to run with Python virtual environment?
First create virtual environment
Expand Down

0 comments on commit d018ccf

Please sign in to comment.