mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 06:12:33 +03:00
76 lines
2.2 KiB
YAML
76 lines
2.2 KiB
YAML
name: Push
|
|
# TODO: Need to be changed into separate configs after
|
|
on: [push, release]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
- name: Install Go
|
|
uses: actions/setup-go@v2
|
|
with:
|
|
go-version: '1.17'
|
|
- name: Build
|
|
run: GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build .
|
|
- name: Upload build
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: micrach
|
|
path: micrach
|
|
retention-days: 1
|
|
|
|
release:
|
|
needs: build
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
# TODO: Need to be removed after separate configs are made
|
|
if: github.ref == 'refs/heads/master'
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
- name: Download build
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: micrach
|
|
path: micrach
|
|
- name: Build docker image and push to GitHub registry
|
|
uses: docker/build-push-action@v1
|
|
with:
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
registry: docker.pkg.github.com
|
|
repository: yanislav-igonin/micrach-go/micrach
|
|
dockerfile: Dockerfile
|
|
tags: latest
|
|
# build_args: CI_COMMIT_TAG=${{ github.event.release.tag_name }}
|
|
|
|
|
|
deploy:
|
|
needs: release
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
# TODO: Need to be removed after separate configs are made
|
|
if: github.ref == 'refs/heads/master'
|
|
|
|
steps:
|
|
- name: Deploy
|
|
uses: appleboy/ssh-action@master
|
|
env:
|
|
REGISTRY: ghcr.io/yanislav-igonin/micrach-go/micrach
|
|
SERVICE_NAME: micrach_app
|
|
with:
|
|
host: ${{ secrets.VPS_HOST }}
|
|
username: ${{ secrets.VPS_SSH_USERNAME }}
|
|
key: ${{ secrets.VPS_SSH_PRIVATE_KEY }}
|
|
script: |
|
|
docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ${{ env.REGISTRY }}
|
|
# docker pull ${{ env.REGISTRY }}:${{ github.event.release.tag_name }}
|
|
docker pull ${{ env.REGISTRY }}:latest
|
|
# docker service update --image ${{ env.REGISTRY }}:${{ github.event.release.tag_name }} ${{ env.SERVICE_NAME }}
|
|
docker service update --image ${{ env.REGISTRY }}:latest ${{ env.SERVICE_NAME }} |