Skip to content

Commit

Permalink
GitHub action (#171)
Browse files Browse the repository at this point in the history
* First action commit

* Test

* Test

* Test

* Test

* Dockerfile build to production

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Test

* Docker push

* Rename coveralls

Co-authored-by: jsansalo <[email protected]>
  • Loading branch information
lucasyarza and jsansaloni authored Nov 28, 2022
1 parent 0b0dbad commit d290312
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 3 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: master

on:
push:
branches:
- 'master'

jobs:
build:
runs-on: ubuntu-20.04

env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_SHA:

steps:
- uses: actions/checkout@v3

- name: docker-compose build
run: make build

- name: Start env
run: APP_COMMAND='tail -f /dev/null' make env-start

- name: Test
run: make test

- name: Coveralls
run: make coveralls

- name: Set outputs
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Check outputs
run: echo ${{ steps.vars.outputs.sha_short }}

- name: Build image
uses: docker/build-push-action@v3
with:
push: false
tags: mercadonatechoss/postoffice:beta, mercadonatechoss/postoffice:master-${{ steps.vars.outputs.sha_short }}
23 changes: 23 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: pr

on: [pull_request]

jobs:
build:
runs-on: ubuntu-20.04

env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- name: docker-compose build
run: make build

- name: Start env
run: APP_COMMAND='tail -f /dev/null' make env-start

- name: Test
run: make test
46 changes: 46 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: mercadonatechoss/postoffice

- name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}

- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{steps.github_release.outputs.changelog}}
files: |
LICENSE
AUTHORS.md
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ENV MIX_ENV prod
WORKDIR /app

COPY . .

RUN mix deps.get --only prod
RUN cd assets && npm install && cd -
RUN npm run deploy --prefix ./assets
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,26 @@ ifeq ($(DOCKER_BRANCH_NAME),)
export DOCKER_BRANCH_NAME := local
endif

ifeq ($(APP_COMMAND),)
export APP_COMMAND := mix phx.server
endif

ifeq ($(MIX_ENV),)
export MIX_ENV := dev
endif

test: ## Run test suite in project's main container
$(DOCKER_COMPOSE_COMMAND) exec -T $(POSTOFFICE_SERVICE) mix test

coveralls: ## Run coveralls in github action
$(DOCKER_COMPOSE_COMMAND) exec -T $(POSTOFFICE_SERVICE) mix coveralls.detail | less -R

build: ## Build project image
$(DOCKER_COMPOSE_COMMAND) build --no-cache --pull

build-prod: ## Build prod image
docker build -t $(DOCKER_NAMESPACE)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)$(DOCKER_BRANCH_NAME) .

env-start: ## Start project containers defined in docker-compose
$(DOCKER_COMPOSE_COMMAND) up -d db
$(DOCKER_COMPOSE_COMMAND) up migrations
Expand All @@ -46,7 +59,7 @@ env-start: ## Start project containers defined in docker-compose
env-stop: ## Stop project containers defined in docker-compose
$(DOCKER_COMPOSE_COMMAND) stop

env-restart: env-stop env-start
env-restart: env-stop env-start ## Restart all containers

env-destroy: ## Destroy all project containers
$(DOCKER_COMPOSE_COMMAND) down -v --rmi all --remove-orphans
Expand Down
7 changes: 6 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
context: ..
dockerfile: docker/Dockerfile.local
image: $DOCKER_NAMESPACE/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG$DOCKER_BRANCH_NAME
environment:
- MIX_ENV
env_file:
- envfiles/local.env
depends_on:
Expand All @@ -31,6 +33,9 @@ services:

app:
image: $DOCKER_NAMESPACE/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG$DOCKER_BRANCH_NAME
environment:
- MIX_ENV
- GITHUB_TOKEN
env_file:
- envfiles/local.env
restart: on-failure
Expand All @@ -42,7 +47,7 @@ services:
condition: "service_completed_successfully"
ports:
- "4001:4000"
command: mix phx.server
command: $APP_COMMAND
volumes:
- '../lib:/app/lib'
- '../priv:/app/priv'
Expand Down
2 changes: 1 addition & 1 deletion docker/envfiles/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ DB_HOSTNAME=db
DB_PORT=5432
GOOGLE_APPLICATION_CREDENTIALS=/app/config/dummy-credentials.json
GCLOUD_PUBSUB_PROJECT_ID=fake
MAX_BULK_MESSAGES=10
MAX_BULK_MESSAGES=10

0 comments on commit d290312

Please sign in to comment.