Skip to content

Commit

Permalink
Create build-and-deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
BaldissaraMatheus authored Mar 8, 2023
1 parent 57f4d60 commit 9d19230
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build and deploy

on:
push:
tags:
- '**'

jobs:
build:
name: Build

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- uses: FranzDiebold/github-env-vars-action@v2

- name: Set major tag name
run: echo "TAG_MAJOR=$(echo $CI_REF_NAME | cut -d. -f1)" >> $GITHUB_ENV

- name: Set major tag name
run: echo "TAG_MINOR=${{ env.TAG_MAJOR }}.$(echo $CI_REF_NAME | cut -d. -f2)" >> $GITHUB_ENV

- name: Build image
run: |
docker build --no-cache \
-t baldissaramatheus/tasks.md:latest \
-t baldissaramatheus/tasks.md:$CI_REF_NAME \
-t baldissaramatheus/tasks.md:${{ env.TAG_MAJOR }} \
-t baldissaramatheus/tasks.md:${{ env.TAG_MINOR }} \
--target base .
- name: Save Docker image as artifact
run: |
docker save -o /tmp/image.tar \
baldissaramatheus/tasks.md:latest \
baldissaramatheus/tasks.md:$CI_REF_NAME \
baldissaramatheus/tasks.md:${{ env.TAG_MAJOR }} \
baldissaramatheus:${{ env.TAG_MINOR }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: image
path: /tmp/image.tar

deploy:
name: Deploy

needs: [build]

runs-on: ubuntu-20.04

steps:
- uses: FranzDiebold/github-env-vars-action@v2

- name: Set major tag name
run: echo "TAG_MAJOR=$(echo $CI_REF_NAME | cut -d. -f1)" >> $GITHUB_ENV

- name: Set major tag name
run: echo "TAG_MINOR=${{ env.TAG_MAJOR }}.$(echo $CI_REF_NAME | cut -d. -f2)" >> $GITHUB_ENV

- name: Download artifact
uses: actions/download-artifact@v2
with:
name: image
path: /tmp

- name: Load Docker image
run: |
docker load --input /tmp/image.tar
docker image ls -a
- name: Push Docker image
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker push --all-tags williarin/secure-mysql-backups

0 comments on commit 9d19230

Please sign in to comment.