Skip to content

Commit

Permalink
3 exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakousa committed Jun 2, 2020
0 parents commit 2338202
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/exec_bash_exercise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release exec_bash_exercise

on:
push:
branches:
- master
paths:
- 'exec_bash_exercise_and_first_volume_exercise/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
env:
SECRET_MESSAGE: ${{ secrets.EXEC_BASH_EXERCISE_SECRET_MESSAGE }}
with:
name: jakousa/exec_bash_exercise
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: latest
buildargs: SECRET_MESSAGE
context: exec_bash_exercise_and_first_volume_exercise
26 changes: 26 additions & 0 deletions .github/workflows/first_volme_exercise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release first_volume_exercise

on:
push:
branches:
- master
paths:
- 'exec_bash_exercise_and_first_volume_exercise/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
env:
SECRET_MESSAGE: ${{ secrets.FIRST_VOLUME_EXERCISE_SECRET_MESSAGE }}
with:
name: jakousa/first_volume_exercise
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: latest
buildargs: SECRET_MESSAGE
context: exec_bash_exercise_and_first_volume_exercise
23 changes: 23 additions & 0 deletions .github/workflows/ports_exercise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release ports_exercise

on:
push:
branches:
- master
paths:
- 'ports_exercise/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: jakousa/ports_exercise
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: latest
context: ports_exercise
9 changes: 9 additions & 0 deletions exec_bash_exercise_and_first_volume_exercise/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:dubnium

ARG SECRET_MESSAGE
ENV SECRET_MESSAGE=$SECRET_MESSAGE

WORKDIR /usr/app
COPY . .

CMD ["node", "index"]
1 change: 1 addition & 0 deletions exec_bash_exercise_and_first_volume_exercise/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Writes "secret message" to file every 15 seconds. Otherwise logs time.
42 changes: 42 additions & 0 deletions exec_bash_exercise_and_first_volume_exercise/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fsPromises = require('fs').promises

const SECRET_MESSAGE = process.env.SECRET_MESSAGE
const filePath = `${__dirname}/logs.txt`
let rounds = 0
let filehandle

const printTimeToFile = async () => {
const startTime = new Date().getTime()
if (filehandle === undefined) {
try {
filehandle = await fsPromises.open(filePath, 'w')
} catch (err) {
console.error('Failed to open file', filePath, err)
return
}
}
rounds++
const GMTString = new Date().toGMTString()
const writeString = (rounds % 5 === 0) ? `Secret message is:\n"${SECRET_MESSAGE}"` : GMTString
try {
await filehandle.appendFile(`${writeString}\n`)
console.log(`Wrote to file ${filePath}`)
} catch (err) {
console.error('Failed to write to file', err)
}

const timeNow = new Date().getTime()
setTimeout(printTimeToFile, 3000 - (timeNow - startTime))
}

printTimeToFile()

const gracefulClose = async () => {
if (filehandle !== undefined) console.log('Closing file') && await filehandle.close()
process.exit(0)
}

process.on('SIGTERM', gracefulClose)
process.on('SIGINT', gracefulClose)


Empty file.
9 changes: 9 additions & 0 deletions ports_exercise/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:alpine

WORKDIR /usr/app

COPY package* ./
RUN npm ci
COPY . .

CMD ["npm", "start"]
10 changes: 10 additions & 0 deletions ports_exercise/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require("express")

const app = express()

const PORT = 80

app.get('*', (req, res) => res.send('Ports configured correctly!!').end())

app.listen(PORT, () =>
console.log(`Listening on port ${PORT}, this means inside of the container. Use -p to map the port to a port of your local machine.`))
Loading

0 comments on commit 2338202

Please sign in to comment.