Skip to content

Commit

Permalink
github docker registry support
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Dec 1, 2020
1 parent 469fc9d commit b75ad4f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REGISTRY="inakri"
REPO_OWNER="izelnakri"
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=localhost
Expand Down
33 changes: 17 additions & 16 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: docker-compose-actions-workflow
name: docker-compose-based-ci
on: push
jobs:
test:
Expand All @@ -8,14 +8,12 @@ jobs:
uses: actions/checkout@v2
- name: Set ENV variables
run: |
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
echo "DOCKER_TAG=paper_trail:$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Expose .env to steps
run: |
sed -i $(echo "s/\$DOCKER_TAG/$DOCKER_TAG/g") .env
cat .env >> $GITHUB_ENV
- name: Docker-compose pull
run: docker-compose pull
echo "REGISTRY=ghcr.io" >> $GITHUB_ENV
echo "REPO_OWNER=$(echo ${GITHUB_REPOSITORY%/*})" >> $GITHUB_ENV
echo "REPO_NAME=$(echo ${GITHUB_REPOSITORY#*/})" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
echo "DOCKER_TAG=$(echo ${GITHUB_REPOSITORY#*/}):$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
Expand All @@ -24,25 +22,28 @@ jobs:
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
key: ${{runner.os}}-buildx-${{github.sha}}
restore-keys: ${{runner.os}}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
username: ${{ secrets.HUB_USERNAME }}
password: ${{ secrets.HUB_KEY }}
registry: ${{env.REGISTRY}}
username: ${{env.REPO_OWNER}}
password: ${{secrets.CR_PAT}}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.HUB_USERNAME }}/${{ env.DOCKER_TAG }}
tags: ${{env.REGISTRY}}/${{env.REPO_OWNER}}/${{env.DOCKER_TAG}}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Docker-compose pull
run: docker-compose pull
- name: Docker-compose up
run: docker-compose -f docker-compose.yaml up -d
run: |
docker-compose -f docker-compose.yaml up -d
- name: Execute tests
run: |
docker-compose exec -T paper_trail mix test test/paper_trail
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ services:
volumes:
- pgdata:/var/lib/postgresql/data
paper_trail:
image: inakri/$DOCKER_TAG
image: $REGISTRY/$REPO_OWNER/$DOCKER_TAG
build:
context: .
dockerfile: Dockerfile
cache_from:
- inakri/$DOCKER_TAG
- $REGISTRY/$REPO_OWNER/$DOCKER_TAG
environment:
POSTGRES_USER: $POSTGRES_USER
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
Expand Down

0 comments on commit b75ad4f

Please sign in to comment.